Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/85188-php-copy-directory/
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/85188-php-copy-directory/#findComment-434620
Share on other sites

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');

Link to comment
https://forums.phpfreaks.com/topic/85188-php-copy-directory/#findComment-434661
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.