dps43633 2016-01-23 08:19
浏览 213
已采纳

如何使用php更新mysql中的longblob图像字段

 if(isset($_POST['submit']) and isset($_GET['slider_id']))
    {
        $date=date('Y-m-j');
        $imgName=$_FILES['image']['name'];
        $cont=file_get_contents($imgName);
         $cont=addslashes($cont);

         if($imgName=="")
         {
        //$imgData =addslashes(file_get_contents($_FILES['image']['name']));
        $res=mysqli_query($connect,'UPDATE `slider_images` SET `image`=\''.$cont.'\' WHERE id=\''.$_GET['slider_id'].'\'');
             if($res)
             {
                 echo "Updated";
             }
             else
             {
                 echo "Not Updated";
             }
        }
     }

Not understanding the real issue behind this and i have refereed many solution's but no success in that.All solution's i found they tell to store images in folder and store the file name in database table.Reason behind storing images in database is, only 4 images are to be stored, so why not to store them in database. Please guide me through this issue. Following is the issue i am talking about. Warning Message Thank's in advance.

  • 写回答

1条回答 默认 最新

  • drngnh708353 2016-01-23 08:35
    关注
    • $_FILES['file']['name'] is the original name of the uploaded file from the user's computer.
    • $_FILES['file']['tmp_name'] will contain the temporary file name of the file on the server. This is just a temporary placeholder until you process the file.

    So you should access the file like this:

    $cont=file_get_contents($_FILES['image']['tmp_name']);
    


    Sidenote: Instead of if($res){ ... } use mysqli_affected_rows() to get number of rows affected by this UPDATE query, like this:
    mysqli_query($connect,"UPDATE `slider_images` SET `image`='".$cont."' WHERE id='".$_GET['slider_id']."'");
    if(mysqli_affected_rows($connect)){
        echo "Updated";
    }else{
        echo "Not Updated";
    }
    

    Here's the reference:

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)