我正在尝试上传一个文件,并拥有它,以便重复的文件名将附加 _0、_1、_2 等。当输入重复的文件时,我收到此错误:
Warning: move_uploaded_file(../data/uploads/../data/uploads/Penguins_0.jpg): failed to open stream: No such file or directory in D:\xampp\htdocs\staff\upload_form.php on line 29
Warning: move_uploaded_file(): Unable to move 'D:\xampp\tmp\php7150.tmp' to '../data/uploads/../data/uploads/Penguins_0.jpg' in D:\xampp\htdocs\staff\upload_form.php on line 29
Upload failed: Could not move uploaded file. [../data/uploads/Penguins_0.jpg]
有人可以帮忙吗?!
$id = "img_" . $_POST['eqId'] . "_" . $_POST['imgId'];
$file = $_FILES[$id];
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $file["name"]);
$extension = strtolower(end($temp));
$dir = "../data/uploads/";
if(($file["type"] == "image/gif")
|| ($file["type"] == "image/jpeg")
|| ($file["type"] == "image/jpg")
|| ($file["type"] == "image/pjpeg")
|| ($file["type"] == "image/x-png")
|| ($file["type"] == "image/png")
&& in_array($extension, $allowedExts)){
if ($file["error"] > 0){
echo "There was an error uploading the file. [Code: " . $file["error"] . "]";
}else{
$fileName = $file['name'];
if (file_exists($dir . $file["name"])){
$appendCount = 0;
while(file_exists($dir . $temp[0] . "_" . $appendCount . "." . $extension)){
$appendCount++;
}
$fileName = ($dir . $temp[0] . "_" . $appendCount . "." . $extension);
}
if(move_uploaded_file($file["tmp_name"], $dir . $fileName )){
echo "success:" . $file["tmp_name"];
}else{
echo "Upload failed: Could not move uploaded file. [" . $fileName . "]";
}
}
}else{
echo "Invalid file type '" . $extension . "'";
}