2017-09-28 77 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'])来检查这些错误图像的属性。