我这个PHP代码:
<?php
// Check for errors
if($_FILES['file_upload']['error'] > 0){
die('An error ocurred when uploading.');
}
if(!getimagesize($_FILES['file_upload']['tmp_name'])){
die('Please ensure you are uploading an image.');
}
// Check filesize
if($_FILES['file_upload']['size'] > 500000){
die('File uploaded exceeds maximum upload size.');
}
// Check if the file exists
if(file_exists('upload/' . $_FILES['file_upload']['name'])){
die('File with that name already exists.');
}
// Upload file
if(!move_uploaded_file($_FILES['file_upload']['tmp_name'], 'upload/' . $_FILES['file_upload']['name'])){
die('Error uploading file - check destination is writeable.');
}
die('File uploaded successfully.');
?>
我需要对现有文件采取“windows”的处理方式——我的意思是如果文件存在,我希望将其更改为文件名,后面有数字 1。
例如:myfile.jpg 已经存在,所以如果你再次上传它会是 myfile1.jpg,如果 myfile1.jpg 存在,它会是 myfile11.jpg 等等...
我该怎么做?我尝试了一些循环,但不幸的是没有成功。