Skyre Posted June 25, 2007 Share Posted June 25, 2007 I'm trying to write a script that simply downloads the daily Ziggy comic. The image URL for today's comic is http://images.ucomics.com/comics/zi/2007/zi070625.gif and the six digits in the filename are today's date. This is what I've written out so far, but it doesn't work. A file gets written, but what gets returned is a HTML page with a 404 error on it. [pre]$filename = $_SERVER['DOCUMENT_ROOT']."/comics/ziggy.gif"; if ($fi=fsockopen("images.ucomics.com",80)) { fputs($fi,"GET /comics/zi/2007/zi070625.gif HTTP/1.0\r\n\r\n"); while(!preg_match("/^\r?\n$/",fgets($fi,1024))); //skip headers if($fo=fopen($filename,"w")) { while(!feof($fi)) { fwrite($fo,fread($fi,65535)); } fclose($fo); } fclose($fi); }[/pre] Link to comment https://forums.phpfreaks.com/topic/57108-solved-downloading-external-images-to-server/ Share on other sites More sharing options...
obsidian Posted June 25, 2007 Share Posted June 25, 2007 If you turn on fopen wrappers to allow for passing URLs to your file manipulation functions, you may be best off simply using the copy() function: <?php $filename = 'zi' . date('ymd') . '.gif'; $new = "/path/to/my/files/{$filename}"; if (!copy("http://images.ucomics.com/comics/zi/2007/{$filename}", "$new)) { // error copying file! } ?> Link to comment https://forums.phpfreaks.com/topic/57108-solved-downloading-external-images-to-server/#findComment-282182 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.