stublackett Posted January 9, 2008 Share Posted January 9, 2008 Hi, New to the forum! Just wondering if anyone can help me with the PHP Copy command, I need it to be simple really in the fact that all I am doing is copying a directory The PHP code is : <?php copy("folder", "folder1"); if (file_exists("folder")) { print("A copy of folder was created.\n"); } ?> This file is located in the root of my web space and I am just using the folder "Folder" as a working example. That PHP code is producing the error : Warning: copy(folder1): failed to open stream: Permission denied in /export2/webroot/users/d4066435/copy.php on line 10 The folder "folder" has the permissions set to "777" and the file copy.php (This file) is also set to 777 Any ideas on how I can get this to work? Or any suggestions on a PHP script that just copys directorys, Cheers! Quote Link to comment https://forums.phpfreaks.com/topic/85188-php-copy-directory/ Share on other sites More sharing options...
duclet Posted January 9, 2008 Share Posted January 9, 2008 You need to make sure the parent folder of "folder" gives you the permission to write. Quote Link to comment https://forums.phpfreaks.com/topic/85188-php-copy-directory/#findComment-434615 Share on other sites More sharing options...
stublackett Posted January 9, 2008 Author Share Posted January 9, 2008 Its on my University main directory, So looks like the permissions were different there, I copied the "copy.php" file into the folder and executed it, It worked! Next problem I've got is, The folder its copied has 0 bytes of space and when clicked to open it opens up in Notepad How do I actually copy the Directory? Quote Link to comment https://forums.phpfreaks.com/topic/85188-php-copy-directory/#findComment-434620 Share on other sites More sharing options...
duclet Posted January 9, 2008 Share Posted January 9, 2008 If I recall correctly, copy is only used for copying files. You generally have to copy file by file. I am pretty sure you can google up such a function that will copy the whole directory. There is a cheat around this but it really isn't recommended. You can do this: system('cp -R folder folder1'); Quote Link to comment https://forums.phpfreaks.com/topic/85188-php-copy-directory/#findComment-434661 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.