我尝试通过jquery图片上传器上传文件,但我希望所有文件都使用变量' fileName'命名上传的文件。因为它目前工作,文件使用其原始名称上传。有什么建议吗?
<?php
// A list of permitted file extensions
$allowed = array('png', 'jpg', 'gif');
$fileName = 'productimage';
if(isset($_FILES['upl']) && $_FILES['upl']['error'] == 0){
$extension = pathinfo($_FILES['upl']['name'], PATHINFO_EXTENSION);
if(!in_array(strtolower($extension), $allowed)){
echo '{"status":"error"}';
exit;
}
if(move_uploaded_file($_FILES['upl']['tmp_name'], 'uploads/'.$_FILES['upl']['name'])){
echo '{"status":"success"}';
exit;
}
}
echo '{"status":"error"}';
exit;
答案 0 :(得分:0)
只需更改
if(move_uploaded_file($_FILES['upl']['tmp_name'], 'uploads/'.$_FILES['upl']['name'])){
到
if(move_uploaded_file($_FILES['upl']['tmp_name'], 'uploads/'.$fileName)){