1

从 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:不愿意采用文件系统存储。

4

1 回答 1

0

好吧,我猜这终于工作了,不知道我必须先将图像保存到服务器,然后再将其保存到 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);
            }   
于 2013-11-04T23:42:44.927 回答