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

Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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