Jump to content

function Copy error :Warning: copy(109.jpg) [function.copy]: failed to...


~n[EO]n~

Recommended Posts

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...

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?

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.... ;D 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 ?

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.