~n[EO]n~ Posted November 30, 2007 Share Posted November 30, 2007 Hi again; I am having problem in copying file... now when i add a folder name i get error Warning: copy(109.jpg) [function.copy]: failed to open stream: No such file or directory in.... <?php for ($i=1; $i<=50; $i++) { $var = $i.".jpg"; echo "<div>$var</div><br />"; echo "<div><img src=\"http://localhost/drawings/3d_drawing_models/images/".$i.".jpg\" /></div>"; // copy file $file = $var; $newfile = "homio/".$var; if (!copy($file, $newfile)) { echo "failed to copy $file...\n"; } } ?> Where I am getting wrong... Link to comment https://forums.phpfreaks.com/topic/79526-function-copy-error-warning-copy109jpg-functioncopy-failed-to/ Share on other sites More sharing options...
aschk Posted November 30, 2007 Share Posted November 30, 2007 Is the script you are running in the same directory as the images? Copy is failing because it can't locate said files. Interesting however that your $i reached 109. Have you changed the top value of $i before you posted the script here? Link to comment https://forums.phpfreaks.com/topic/79526-function-copy-error-warning-copy109jpg-functioncopy-failed-to/#findComment-402768 Share on other sites More sharing options...
~n[EO]n~ Posted November 30, 2007 Author Share Posted November 30, 2007 Actually this code runs online, i changed the path while posting and the value of $i too.. Here what I am trying to do is copy the file from website (say xyz.com) to my pc... There are around 5000 images. It could be done manually (will take lot of time for me) but I thought let PHP handle this.... why waste time.. Is there other way ? Now I changed the $var path to $file = "http://xyz.com/3d_models/images/".$var; and got this error. Warning: copy(http://xyz.com/3d_models/images/117.jpg) [function.copy]: failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error in C:\wamp\www\freaks\test.php on line 20 What does this error mean any idea ? Link to comment https://forums.phpfreaks.com/topic/79526-function-copy-error-warning-copy109jpg-functioncopy-failed-to/#findComment-402771 Share on other sites More sharing options...
aschk Posted November 30, 2007 Share Posted November 30, 2007 copy will only work on a local file system. I believe you're going to need a stream, or file_get_contents might work for you (over tcp). file_get_contents("http://www.someonesdomain.com/images/1.jpg"); You'll probably want to use the FILE_BINARY flag, and once you have the BINARY string then you need to write it to a file and rename it to whatever you want. note: i'm guessing and haven't tested this. I'll leave that to you. Link to comment https://forums.phpfreaks.com/topic/79526-function-copy-error-warning-copy109jpg-functioncopy-failed-to/#findComment-402776 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.