Copy Files to another folder PHP

2019-09-15 15:48发布

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?

4条回答
姐就是有狂的资本
2楼-- · 2019-09-15 16:07
copy("folder1/file.format" , "folder2/file.format");

sample:

copy("../folder1/my.jpg" , "folder2/my.jpg");
查看更多
男人必须洒脱
3楼-- · 2019-09-15 16:14

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.

查看更多
Bombasti
4楼-- · 2019-09-15 16:30

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

查看更多
我欲成王,谁敢阻挡
5楼-- · 2019-09-15 16:32

you can use copy function in php

copy('PATTERN/index.php', 'USERNAME/index.php');
查看更多
登录 后发表回答