duancenxiao0482 2013-11-04 13:29
浏览 48
已采纳

将图像(NSData)插入BLOB字段

From iOS app to php script, I want to store a bench of images as BLOB types:

 $profile_images = $_REQUEST['profile_images_array'];//get the array of images

        //loop the images and store them one by one
        foreach($profile_images as $image){ 
        $sqlinsertimages = "insert into profile_images (id_client,image) Values ('".$id."',mysql_real_escape_string('".$image."'))";
        $result = mysql_query($sqlinsertimages);

        }   

The insert would work fine if I eliminate the image field (which is BLOB type), so the issue is obviously with the saving BLOB types in the table.

How to store properly the images in PHP as BLOB?

PS: not willing to adopt the file system storage.

  • 写回答

1条回答 默认 最新

  • doukunsan5553 2013-11-04 15:42
    关注

    Ok, I guess that work finally, didn't knew that I had to save the image to the server before saving it to MySQL:

                foreach($profile_images as $image){ 
                    //Get the file as a string before inserting it to table
                    $content = file_get_contents($image);
                    $content = mysql_real_escape_string($content);
                    $sqlinsertimages = "insert into profile_images (id_client,image) Values ('".$id."','".$content."')";
    
                    $result = mysql_query($sqlinsertimages);
                }   
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 matlab中频率调制法代码的解读
  • ¥15 ceph的对象、块、文件相关问题求解答
  • ¥50 如果使用python进行ERA5 10米风场预报检验
  • ¥15 navicat解析mysql密码
  • ¥15 SDAPI(关键词-table)
  • ¥15 unity安卓打包出现问题
  • ¥20 安装catkin时遇到了如下问题请问该如何解决呢
  • ¥15 VAE模型如何输出结果
  • ¥15 编译python程序为pyd文件报错:{"source code string cannot contain null bytes"
  • ¥20 关于#r语言#的问题:广义加行模型拟合曲线后如何求拐点
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部