Jump to content

copy() error


xProteuSx

Recommended Posts

I am trying to copy an existing file into a newly created directory using PHP, and am getting errors.  Here is the code:

 

 

mkdir('../user/dude1/');
mkdir('../user/dude1/images/');
chmod('../user/dude1/images/', 0777);
$userdir = '../user/dude1/';
$imgdir = '../user/dude1/images/';
$copyfile = '../user/index.html';
copy($copyfile,$userdir);
copy($copyfile,$imgdir);
 
If I run a file_exists() on $userdir, $imgdir, or $copyfile, they all come back true, and all of these directories and files exist before the copy() command has run.  Here is the error that I get:
 
Warning: copy(../user/dude1) [function.copy]: failed to open stream: Is a directory in addcollection.php on line 154
Warning: copy(../user/dude1/images/) [function.copy]: failed to open stream: Is a directory in addcollection.php on line 155
 
I have also tried using the following file structure:
 
$userdir = '/home/username/public_html/user/dude1';  (for example)
 
... and I still get the same message, even though I am using things from the 'root'.
 
I have tried a lot of different variations of file structure, names, etc. and I can't get this to work.  Your help would be much appreciated.  Thank you in advance.
Link to comment
https://forums.phpfreaks.com/topic/275053-copy-error/
Share on other sites

Figured this out about 12 seconds after I posted it.  I need to copy the file to a file, and not to a directory.  So like this:

 

 

mkdir('../user/dude1/');
mkdir('../user/dude1/images/');
chmod('../user/dude1/images/', 0777);
$userdir = '../user/dude1/index.html';
$imgdir = '../user/dude1/images/index.html';
$copyfile = '../user/index.html';
copy($copyfile,$userdir);
copy($copyfile,$imgdir);
 
Voila!
Link to comment
https://forums.phpfreaks.com/topic/275053-copy-error/#findComment-1415578
Share on other sites

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.