Jump to content

copy() error


xProteuSx
Go to solution Solved by 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
Share on other sites

  • Solution

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