Php 在存储之前更改图像名称

Php 在存储之前更改图像名称,php,Php,这是我的密码。我想在将文件存储到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

这是我的密码。我想在将文件存储到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.');

通过生成一个新的唯一字符串并从上传的文件名中获取扩展名,创建一个新的文件名,只需将其传递到
move\u uploaded\u file

$extension = pathinfo($_FILES['file_upload']['name'], PATHINFO_EXTENSION);
$nFileName = md5(time()).'.'.$extension;


// Upload file
if(!move_uploaded_file($_FILES['file_upload']['tmp_name'], '../uploads/profilepics/' . $nFileName)){
    die('Error uploading file - check destination is writeable.');
}

在手册中查找move_uploded_文件谢谢它工作了-我需要7分钟才能将您的答案勾选为正确:)