第二次用到同样文件名的图片,进行上传时提示文件已存在,路径也保存不了数据库,文件名也无法存入数据库,导致不显示。,请教大神在哪里加代码处理这个问题?
第二个问题,在哪里加代码压缩图片文件大小
<?phpif (count($_FILES)) { $retFiles = uploadFile("file"); if ($retFiles['status'] == 1) { echo $retFiles['message']; } else if ($retFiles['status'] == 0) { echo "Upload: " . $retFiles["name"] . "<br />"; echo "Type: " . $retFiles["type"] . "<br />"; echo "Size: " . ($retFiles["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $retFiles["temp"] . "<br />"; echo "Stored in: " . "../upload/" . $retFiles["name"]; }}
function uploadFile($fileName){ $files = $_FILES[$fileName]; if (!in_array($files["type"], array("image/gif","image/jpeg","image/pjpeg","image/jpeg", "image/png"))) { return array("status" => 1, "message" => "Uploaded image format is not correct"); } if ($files["error"] > 0) { return array("status" => 1, "message" => "upload error"); } if (file_exists("../upload/" . $files["name"])) { return array("status" => 1, "message" => $files["name"]." already exiss"); } move_uploaded_file($_FILES['file']['tmp_name'], '../upload/'.iconv("UTF-8", "gbk",$_FILES['file']['name'])); return array("status" => 0, "name" => $files["name"], "type" => $files["type"], "size" => $files['size']/1024, "temp" => $files["tmp_name"]); }