~n[EO]n~ Posted December 3, 2007 Share Posted December 3, 2007 I have this code, it shows the images from one of my site and i want to copy it in my pc.. but file_get_contents is not working... <?php // fetch images for ($i=11; $i<=50; $i++) { $var = $i.".jpg"; echo "<div>$var</div><br />"; echo "<div><img src=\"http://xxxxx.com/models/images/".$i.".jpg\" /></div>"; // copy file $file = file_get_contents("http://xxxxx.com/models/images/".$i.".jpg"); $newfile = "newfolder/".$var; if (!copy($file, $newfile)) { echo "failed to copy $file...\n"; } } ?> Images are displaying fine, but copy is not working... Any help please Thanks Link to comment https://forums.phpfreaks.com/topic/79938-file_get_contents-and-copy-not-workinghelp-please/ Share on other sites More sharing options...
rajivgonsalves Posted December 3, 2007 Share Posted December 3, 2007 does the destination folder have proper write privilages Link to comment https://forums.phpfreaks.com/topic/79938-file_get_contents-and-copy-not-workinghelp-please/#findComment-404891 Share on other sites More sharing options...
~n[EO]n~ Posted December 3, 2007 Author Share Posted December 3, 2007 yes it has, will this work, i have doubt now... and btw i get this error [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 500 Internal Server Error in C:\wamp\www\freaks\test.php on line 18 Link to comment https://forums.phpfreaks.com/topic/79938-file_get_contents-and-copy-not-workinghelp-please/#findComment-404898 Share on other sites More sharing options...
rajivgonsalves Posted December 3, 2007 Share Posted December 3, 2007 well you can use copy only from a file not on a string your code should use file_put_contents instead of copy if you want to write it to a file Link to comment https://forums.phpfreaks.com/topic/79938-file_get_contents-and-copy-not-workinghelp-please/#findComment-404902 Share on other sites More sharing options...
~n[EO]n~ Posted December 3, 2007 Author Share Posted December 3, 2007 Finally, I think this will work... but now i am getting another problem, it shows 5 images from 11.jpg to 15.jpg but it only copies the first one... and i get this error on other images.. Warning: stream_copy_to_stream() expects parameter 1 to be resource, boolean given in C:\wamp\www\freaks\test.php on line 20 but there is no line 20 <?php // fetch images for ($i=11; $i<=15; $i++) { $var = $i.".jpg"; echo "<div>$var</div><br />"; echo "<div><img src=\"http://xxxxx.com/models/images/".$i.".jpg\" /></div>"; // copy file $src = fopen("http://xxxxx.com/models/images/".$i.".jpg", 'r'); $dest2 = fopen("homio/".$var, 'w'); // copy through stream.... echo stream_copy_to_stream($src, $dest2) . " bytes copied \n"; } ?> Link to comment https://forums.phpfreaks.com/topic/79938-file_get_contents-and-copy-not-workinghelp-please/#findComment-404910 Share on other sites More sharing options...
rajivgonsalves Posted December 3, 2007 Share Posted December 3, 2007 why not just try <?php // fetch images for ($i=11; $i<=15; $i++) { $var = $i.".jpg"; echo "<div>$var</div><br />"; echo "<div><img src=\"http://xxxxx.com/models/images/".$i.".jpg\" /></div>"; file_put_contents("homio/".$var,file_get_contents("http://xxxxx.com/models/images/".$i.".jpg")); // copy through stream.... } ?> Link to comment https://forums.phpfreaks.com/topic/79938-file_get_contents-and-copy-not-workinghelp-please/#findComment-404914 Share on other sites More sharing options...
~n[EO]n~ Posted December 3, 2007 Author Share Posted December 3, 2007 It only copies the first one, same as stream_copy.... Link to comment https://forums.phpfreaks.com/topic/79938-file_get_contents-and-copy-not-workinghelp-please/#findComment-404923 Share on other sites More sharing options...
rajivgonsalves Posted December 3, 2007 Share Posted December 3, 2007 any errors reported Link to comment https://forums.phpfreaks.com/topic/79938-file_get_contents-and-copy-not-workinghelp-please/#findComment-404932 Share on other sites More sharing options...
~n[EO]n~ Posted December 3, 2007 Author Share Posted December 3, 2007 First one gets copied nicely then below other images i get this error Warning: file_get_contents(http://xxxxx.com/models/images/12.jpg) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 500 Internal Server Error in C:\wamp\www\freaks\test.php on line 18 and same for other images 13.jpg... and so on and line 18 is file_put_contents................. Link to comment https://forums.phpfreaks.com/topic/79938-file_get_contents-and-copy-not-workinghelp-please/#findComment-404935 Share on other sites More sharing options...
rajivgonsalves Posted December 3, 2007 Share Posted December 3, 2007 basically it cannot get those images from the url are they displaying properly in the browser ? Link to comment https://forums.phpfreaks.com/topic/79938-file_get_contents-and-copy-not-workinghelp-please/#findComment-404937 Share on other sites More sharing options...
~n[EO]n~ Posted December 3, 2007 Author Share Posted December 3, 2007 Yes all images get displayed and name is also in sequence... it only copies the first one. Any other idea ? Link to comment https://forums.phpfreaks.com/topic/79938-file_get_contents-and-copy-not-workinghelp-please/#findComment-404938 Share on other sites More sharing options...
~n[EO]n~ Posted December 4, 2007 Author Share Posted December 4, 2007 BUMP-ed Link to comment https://forums.phpfreaks.com/topic/79938-file_get_contents-and-copy-not-workinghelp-please/#findComment-405869 Share on other sites More sharing options...
rajivgonsalves Posted December 4, 2007 Share Posted December 4, 2007 well if you give me the exact code maybe I could help the actual url etc. Link to comment https://forums.phpfreaks.com/topic/79938-file_get_contents-and-copy-not-workinghelp-please/#findComment-405891 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.