ここで奇妙な状況に直面しています。たとえば、宛先フォルダーをスキャンして重複するファイル名をチェックし、重複する名前の名前を反復番号に変更する、高度なマルチパートファイルアップロードスクリプトがあります。ここでの問題は、何らかの理由で、重複が送信されない場合、スクリプトは緑色のライトで通過しますが、重複が入力された場合、スクリプトは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;
}
}
}
}
?>