Copy Files to another folder PHP

2019-09-15 15:43发布

问题:

So, recently I am working on a small social network, and I stuck at a beginner-fail :(

When a new User is created, a new FOLDER - named like the User - is created in the current folder (/Users). In the current folder(/Users) is also a folder named PATTERN, where a index.php is included.

When a new user is created with mkdir($Username, 0777) I also want to COPY the index.php from the PATTERN-Folder (/PATTERN) into the new User folder (/$Username).

It just doesn't copy in my tries - how would you do that?

回答1:

You can use copy() to copy a file with PHP:

if (!copy('PATTERN/index.php', $Username.'/index.php')) {
    echo "failed to copy file...";
}

If this does not work, you might have a problem with your code, access rights, or something else. Without your code and the exact description of the error message (if any) it will be hard to help you.



回答2:

you can use copy function in php

copy('PATTERN/index.php', 'USERNAME/index.php');


回答3:

you can use copy function

   // Will copy abc/a.php to xyz/x.php
   copy('abc/a.php', 'xyz/x.php');

Docs link: http://www.php.net/manual/en/function.copy.php



回答4:

copy("folder1/file.format" , "folder2/file.format");

sample:

copy("../folder1/my.jpg" , "folder2/my.jpg");