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

如何使用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 本地测试网站127.0.0.1 已拒绝连接,如何解决?(标签-ubuntu)
  • ¥50 Qt在release捕获异常并跟踪堆栈(有Demo,跑一下环境再回答)
  • ¥30 python,LLM 文本提炼
  • ¥15 关于将inet引入的相关问题
  • ¥15 关于一个倒计时的操作和显示设计
  • ¥15 提问STK的问题,哪位航天领域的同学会啊
  • ¥15 苹果系统的mac m1芯片的笔记本使用ce修改器使用不了
  • ¥15 单相逆变的电压电流双闭环中进行低通滤波PID算法改进
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 如何卸载arcgis 10.1 data reviewer for desktop