faqts : Computers : Programming : Languages : PHP : Function Libraries : Image

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

5 of 5 people (100%) answered Yes
Recently 3 of 3 people (100%) answered Yes

Entry

Anybody know how or if ImageCreateFrom__() function works with URLs? Error: Can't read image when using http://

Feb 20th, 2001 13:17
Mike Boucher, http://www.php.net/manual


In response to my own post: 
Maybe this is common knowledge but here is how I solved my 
problem. Hopefully this will help out seeing how I couldn't find any 
other articles on this topic with a solution. 
This seems to work pretty well. Displays in browser and QT 
Picture Viewer but for some reason Photoshop won't open it. 
Translation error. Since I'm just using it to cache the image for 
when our content provider's server goes down, not being able to 
edit the images in PS is no biggie there. (This might even be due 
to the fact that the image is being created on a Windows NT 
machine and I am trying to open it on a MAC computer. Might have 
to check into that further.)
And now on with the code. Pretty simple and straight forward.
<?
$si = fopen($imagePathURL, "r"); // open URL 
$serverImg = fread($si, 1000000); // read contents 
fclose($si); // close file 
/* open file to save to (w+ creates if file does not exist || b opens 
binary safe [Win32]) Seemed to work fine with out the 'b' on 
Windows NT but just to be safe. */ 
$si = fopen($saveImgTo, "w+b"); 
fwrite($si, $serverImg); // write contents to file 
fclose($si); // close file 
?>
Hope this helps somebody in the future.
mb
ampmedia.net