Jump to content

Copy files in one directory to another?


Genesis730

Recommended Posts

How can I transfer files from one directory to another?? Here's my code, however I get this error...

"The second argument to copy() function cannot be a directory in *WAMP Dir*/process.php on line 141" Line 141 is - copy($tempdir, $leaguedir);

 

$tempdir = $_SERVER['DOCUMENT_ROOT']."temp/index.php";
$enddir = $_SERVER['DOCUMENT_ROOT'].$dir;
copy($tempdir, $enddir);

 

I planned on doing this several times, one for each file, however if anyone knows how to do the entire directory, that would be awesome!

Link to comment
https://forums.phpfreaks.com/topic/206736-copy-files-in-one-directory-to-another/
Share on other sites

It appears, with the script on http://us2.php.net/copy by nensa at zeec dot biz as if the script is trying to look for the initial and final directory where the script is located. Here is the error

 

Warning: fopen(*WAMP Dir*/temp/) [function.fopen]: failed to open stream: No such file or directory in *WAMP Dir*/process.php on line 141, line 141 is the start of the script "$fsrc = fopen($tempdir,'r');"

 

Any ideas?

So I think I'm close, now I get a permission error, specifically " [function.fopen]: failed to open stream: Permission denied" here's the code...

        $fsrc = fopen($tempdir,'r'); 
        $fdest = fopen($leaguedir,'w+'); 
        $len = stream_copy_to_stream($tempdir,$leaguedir); 
        fclose($fsrc); 
        fclose($fdest); 
        return $len; 

 

Any ideas?

So I think I'm close, now I get a permission error, specifically " [function.fopen]: failed to open stream: Permission denied" here's the code...

        $fsrc = fopen($tempdir,'r'); 
        $fdest = fopen($leaguedir,'w+'); 
        $len = stream_copy_to_stream($tempdir,$leaguedir); 
        fclose($fsrc); 
        fclose($fdest); 
        return $len; 

 

Any ideas?

 

If its a permission problem, then make sure your server allows for such actions through a php script.

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.