$file_path = "files/";
$file_temps = array("temp_1_file.txt", "temp_2_file.txt");
$file_names = array("new_file.txt", "temp_1_file.txt");
foreach($file_temps as $file_temp){
foreach($file_names as $file_name){
move_uploaded_file($file_temp, $file_path."/".$file_name);
break;
}<br>
}
<br>
这只上传一个文件,我不明白。请帮助,提前致谢。
答案 0 :(得分:0)
这种情况正在发生,因为您在第二个break
内使用了foreach
。你可以使用类似的东西:
$files = array(
"temp_1_file.txt" => "files/new_file.txt",
"temp_2_file.txt" => "files/temp_1_file.txt"
);
foreach($files as $fileTemp => $fileName){
move_uploaded_file($fileTemp, $fileName);
}
或如果您想使用2个数组:
$filePath = 'files/';
$fileTemps = array("temp_1_file.txt", "temp_2_file.txt");
$fileNames = array("new_file.txt", "temp_1_file.txt");
foreach($fileTemps as $key => $fileTemp){
move_uploaded_file($fileTemp, $filePath . $fileNames[$key]);
}