[英]How do i move a file from one directory to another on the same server on PHP
I'm trying to copy one file from a directory to another upon execution of an sql query but it doesn't work.我试图在执行 sql 查询时将一个文件从一个目录复制到另一个,但它不起作用。
if($result){
$path = "forms/uploads/";
$file = $path.$request_name."docx";
if(file_exists($file)){
move_uploaded_file($file, "forms/requests/") ;
}
echo 400;
The $path is the directory where the file currently exists. $path 是文件当前所在的目录。
You can try use copy function and unlink old file您可以尝试使用复制 function 并取消链接旧文件
https://www.php.net/manual/en/function.copy.php https://www.php.net/manual/en/function.copy.php
if($result){
$path = "forms/uploads/";
$file = $path.$request_name."docx";
$newfile = $path.$request_name."docx";
if(file_exists($file)){
if (!copy($file, "forms/requests/".$newfile)) {
echo "failed to copy $file...\n";
}
unlink($file);
}
echo 400;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.