我在这里遇到了一个奇怪的情况:我有一个高级的多部分文件上传脚本,例如,它通过扫描目标文件夹来检查重复的文件名,然后用迭代号重命名重复的名称。现在,这里的问题是,由于某种原因,如果没有提交副本,脚本会通过绿灯,但是如果输入了副本,脚本将在 move_upload_file 部分返回 false,但是,仍然设法在目标文件夹中创建正确的副本. 我只是想知道,为什么以及如何 move_upload_file 函数返回 false,但仍然继续移动文件?
这是脚本的简化片段,只是想指出问题所在:
<?php
//I'll loop all the files, which are submitted (in array)
foreach($_FILES['myFiles']['tmp_name'] as $key => $tmp_path) {
//Alot of stuff (most likely unrelated) happens here
//filepath contains both destination folder and filename
$filepath = $destination_folder.$filename;
if (file_exists($filepath)) {
$duplicate_filename = true;
//Some more stuff happens here. Then comes the actual moving part. Before this we have found duplicates
//for this upload file and counted proper duplicate value.
$file_increment = $num_of_filename_duplicates + 1;
while ($duplicate_filename == true) {
if(file_exists($filepath)) {
//Separate filename parts and make new duplicate name with increment value
$info = pathinfo($filename);
$basename = basename($filename,'.'.$info['extension']);
$newfilename = $basename."(".$file_increment.").".$info['extension'];
$filepath = $destination_folder.$newfilename;
//Now, this returns me false, but still creates the file into destination
if(move_uploaded_file($tmp_path, $filepath)) {
$file_success = true;
$file_increment++;
}
//So thats why this is true and I'll get the file_error
else {
$file_error = "File error: Uploading of the file failed.";
break;
}
}
else {
$duplicate_filename = false;
}
}
}
}
?>