xProteuSx Posted February 28, 2013 Share Posted February 28, 2013 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 154Warning: 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. Quote Link to comment https://forums.phpfreaks.com/topic/275053-copy-error/ Share on other sites More sharing options...
timothyarden Posted February 28, 2013 Share Posted February 28, 2013 Not sure its been a while since Ive done file work but from memory you need to use fopen() to open the file assign it to a variable and put it in the first parameter - read the manual on php.net regarding fopen() php.net/fopen & also php.net/copy Quote Link to comment https://forums.phpfreaks.com/topic/275053-copy-error/#findComment-1415577 Share on other sites More sharing options...
Solution xProteuSx Posted February 28, 2013 Author Solution Share Posted February 28, 2013 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! Quote Link to comment https://forums.phpfreaks.com/topic/275053-copy-error/#findComment-1415578 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.