【问题标题】:Insert images (NSData) into BLOB fields将图像 (NSData) 插入 BLOB 字段
【发布时间】:2013-11-05 07:55:40
【问题描述】:

从 iOS 应用程序到 php 脚本,我想将一组图像存储为 BLOB 类型:

 $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);

        }   

如果我消除图像字段(这是 BLOB 类型),插入会正常工作,所以问题显然是在表中保存 BLOB 类型。

如何将 PHP 中的图像正确存储为 BLOB?

PS:不愿意采用文件系统存储。

【问题讨论】:

  • 你遇到了什么问题?确保您的表满足数据类型存储要求:docs.oracle.com/cd/E17952_01/refman-5.6-en/…
  • 嗨,是的,图像字段是 BLOB 类型,确实我使用的是 MySQL
  • 它是BLOB,但是,什么类型的BLOB?您不能在 BLOB 类型字段中存储大于 64KB 的数据。你确定你的桌子符合要求吗?再说一次,你到底遇到了什么问题?有任何错误信息吗?
  • 我将 BLOB 类型更改为 longblob,对于错误消息,我应该在哪里看到?哪个文件,我正在使用 MAMP。谢谢。
  • 更改为 $result = mysql_query($sqlinsertimages) OR die(mysql_error());

标签: php mysql ios blob


【解决方案1】:

好吧,我猜终于成功了,不知道我必须先将图像保存到服务器,然后才能将其保存到 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);
            }   

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-08
    • 2019-01-26
    • 2015-11-03
    • 2021-02-17
    • 2013-03-21
    • 2017-01-12
    相关资源
    最近更新 更多