我正在尝试在上传时更改文件名。该映像名称是我要插入数据库4f9e9118b753cIMAGE.jpeg
中的名称,但是文件系统中仍然仅保留IMAGE.jpeg
(原始映像名称)。以下是我正在使用的部分代码:
if (isset($_FILES['userupload']['name'])) {
$uploaddir = "uploads/";
switch($_FILES['userupload']['type']) {
case "image/gif":
case "image/jpeg":
case "image/jpg":
case "image/png":
$uploaddir .= 'pictures/';
break;
}
foreach($_FILES as $userupload){
$t = uniqid();
$type = $userupload['type'];
$name = $userupload['name'];
$size = $userupload['size'];
$image_name = $t."$name";
if(move_uploaded_file($_FILES['userupload']['tmp_name'], $uploaddir . $file)) {
$query = "INSERT INTO users ( image_name ) VALUES ( '$image_name' )";
mysql_query($query) or die (mysql_error());
最佳答案
您需要插入此行
move_uploaded_file($_FILES["userupload"]["tmp_name"],$uploaddir.$image_name);
查询之前