這是我的代碼。我想在將文件存儲到uploads文件夾之前更改文件名,但似乎無法弄清楚。謝謝。儲存前更改圖像名稱
// 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 filetype
if($_FILES['file_upload']['type'] != 'image/png'){
die('Unsupported filetype uploaded.');
}
// Check filesize
if($_FILES['file_upload']['size'] > 700000){
die('File uploaded exceeds maximum upload size.');
}
// Check if the file exists
if(file_exists('../uploads/profilepics/' . $_FILES['file_upload']['name'])){
die('File with that name already exists.');
}
// Upload file
if(!move_uploaded_file($_FILES['file_upload']['tmp_name'], '../uploads/profilepics/' . $_FILES['file_upload']['name'])){
die('Error uploading file - check destination is writeable.');
}
// File uploaded succesfully - upload to server and to DB
die('File uploaded successfully.');
手動 –