重命名上传的图像不起作用

时间:2012-04-30 13:57:46

标签: php mysql image upload

我正在尝试在上传时更改文件名。此图像名称是我要插入数据库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());

1 个答案:

答案 0 :(得分:1)

您需要插入此行

move_uploaded_file($_FILES["userupload"]["tmp_name"],$uploaddir.$image_name);
查询前的