doujilou3903 2017-09-28 04:53
浏览 389

使用tmp_name的PHP文件上载问题

Issue with uploading some Images. I was trying to store image in mysql blob type. It was successful for some images but for some other images, it results in error.

warning in logs are as below:

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 file code:

            $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')";
  • 写回答

1条回答 默认 最新

  • dougu3591 2017-09-28 05:12
    关注

    but for some other images, it results in error

    This is the point.... Maybe you should add a var_dump($_FILES['userfile']) to check the property of those error images.

    评论

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能