~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 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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"; } ?> Quote Link to comment 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.... } ?> Quote Link to comment 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.... Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 3, 2007 Share Posted December 3, 2007 any errors reported Quote Link to comment 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................. Quote Link to comment 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 ? Quote Link to comment 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 ? Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted December 4, 2007 Author Share Posted December 4, 2007 BUMP-ed Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.