2013-11-04 40 views
1

从iOS应用到PHP脚本,我想图像的板凳存储为BLOB类型:插入图像(NSData的)到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类型有关。

如何正确地将图像作为BLOB存储在PHP中?

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

+0

你遇到什么问题?确保你的表符合数据类型存储要求:http://docs.oracle.com/cd/E17952_01/refman-5.6-en/storage-requirements.html#idm47627770414160 – erkanyildiz

+0

嗨,是的图像字段是BLOB类型,的确是我我正在使用MySQL – Malloc

+0

它是BLOB但是,BLOB是什么类型?您不能在BLOB类型字段中存储大于64KB的数据。你确定你的桌子符合要求吗?再说一次,你遇到了什么问题?任何错误消息? – erkanyildiz

回答

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