我上传一次时遇到问题,但如果图像文件退出,则无法将更多图像添加到文件夹中,它只看到消息“已经上传”:让我们看看我的代码如下
<?php
$name = pathinfo($_FILES["file"]["name"], PATHINFO_FILENAME);
$extension = pathinfo($_FILES["file"]["name"], PATHINFO_EXTENSION);
if ($_FILES["file"]["error"] > 0) {
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
} else {
if (file_exists("upload/" . $_FILES["file"]["name"])) {
$increment = ''; //start with no suffix
while (file_exists($name . $increment . '.' . $extension)) {
$increment++;
}
$basename = $name . $increment . '.' . $extension;
move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $basename);
echo "already upload";
} else {
move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
?>