我如何使用php将一个文件从一个目录复制到另一个目录
You can use
copy
— Copies file Example from Manual:
$file = 'example.txt';
$newfile = 'example.txt.bak';
if (!copy($file, $newfile)) {
echo "failed to copy $file...\n";
}
使用rename()
。
rename ("/var/www/files/file.txt", "/var/www/sites/file.txt");
rename('path/to/file/file.ext', 'path2/to2/file2/file.ext');
If you are moving a file just uploaded, use http://php.net/manual/en/function.move-uploaded-file.php instead of rename(). It gives you some added security.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.