Copy Files to another folder PHP

て烟熏妆下的殇ゞ 提交于 2019-12-11 18:41:39

问题


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


来源:https://stackoverflow.com/questions/21526046/copy-files-to-another-folder-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!