2017-02-04 88 views
-1

我正在嘗試使用表單發佈新帖子。我無法在MySQL上插入圖像

在這種形式中,我有4個參數(標題,描述/標籤,完整描述和圖像)。當我使用後端PHP API從應用程序接收數據時,我在MySQL數據庫中插入一行。

基本上,我可以插入行的一切,除了圖像。這裏是我的代碼:

<?php 
try 
{ 
    $db = new PDO('mysql:host=localhost;dbname=social;charset=utf8', 'root', 'root'); 
} 
catch(Exception $e) 
{ 
    die('Erreur : '.$e->getMessage()); 
} 
// $security = new White\Security; 

$post = $_POST; 
$file_tmp= $_FILES['img']; 
$img = file_get_contents($file_tmp); 
echo $img; 
$title = addslashes($post['title']); 
$description = addslashes($post['description']); 
$fullDesc = addslashes($post['full']); 

$sql = "INSERT INTO posts (title, description, img, fullDesc, likes) VALUES ('$title', '$description', '$img', '$fullDesc', 0)"; 
echo $sql; 
$db->exec($sql); 
$status = array('status' => "success"); 
// header("Access-Control-Allow-Origin: *"); 
header("Location: form.php"); 

和,這裏是我的表:https://i.stack.imgur.com/Ly3gP.png

我搜索在谷歌的東西,這將解決我的問題,但我什麼也沒找到,所以這就是爲什麼我問這個問題,在這個論壇上!

+0

你真的想把圖像放到表中嗎?爲什麼不只是上傳,然後保存在表中只上傳圖像的路徑? – RIKI

+0

您是否嘗試過使用準備的陳述? –

+0

@OTARIKI因爲,我有一個無限的DB,只有15GB的磁盤。 –

回答

-1

mysql_escape_string($ img); 可能是你可以在百度搜索,當你找不到任何東西..

+0

OP哪裏需要添加這個轉義,你能否提供一個鏈接到文檔(以及逃生的描述)?這個答案是非常短的... –

+0

我使用PHP 7,所以沒有MySQL擴展 –