2017-09-28 118 views
1

上傳問題部分圖片。我試圖在mysql blob類型中存儲圖像。它對一些圖像是成功的,但對於其他一些圖像,則會導致錯誤。tmp_name的PHP文件上傳問題

在記錄警告情況如下:

Warning: fopen(): Filename cannot be empty in C:\xampp\htdocs\KITSW zone\Modules\Timeline\Admin\image_post.php on line 32 

Warning: fread() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\KITSW zone\Modules\Timeline\Admin\image_post.php on line 33 

Warning: fclose() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\KITSW zone\Modules\Timeline\Admin\image_post.php on line 35 

PHP文件代碼:

  $filename = $_FILES['userfile']['name']; 
      $tmpname = $_FILES['userfile']['tmp_name']; 
      $file_size = $_FILES['userfile']['size']; 
      $file_type = $_FILES['userfile']['type']; 
      $ext = pathinfo($filename, PATHINFO_EXTENSION); 

      $fp  = fopen($tmpname, 'r'); 
      $content = fread($fp, filesize($tmpname)); 
      $content = addslashes($content); 
      fclose($fp); 

      $final = "INSERT INTO `files`(`by_user`, `name`, `type`, `size`, `data`, `category`, `categoryid`) 
      VALUES('$by_user', '$filename','$file_type','$file_size','$content','timeline','$inserted')"; 
+0

您使用的是Ajax嗎?或只是從HTML發佈? –

+0

@Nandan Bhat使用Jquery –

+0

您在標記中使用

回答

0

但對於其他一些圖像,它導致錯誤

這是點.... 也許你應該添加一個var_dump($ _ FILES ['userfile'])來檢查這些錯誤圖像的屬性。