2013-11-04 54 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); 
      }