2017-02-25 56 views
0

我試圖存儲在MySQL中的圖像和得到警告警告:非法串偏移「啞劇」

非法抵消下面的代碼「默」

<?php 
ini_set('display_errors',1); 
error_reporting(E_ALL); 
$conn = mysql_connect("localhost","root",""); 
$db = mysql_select_db("imagestore",$conn); 
if(!$db) 
{ 
    echo mysql_error(); 
} 
$rollNo = $_POST['rollNo']; 
$image = addslashes (file_get_contents($_FILES['image']['tmp_name'])); 
$image_s=getimagesize($_FILES['image']['tmp_name']); 
$imgtype = $image['mime']; 
$q = "INSERT INTO students VALUES('','$rollNo','$image','$imgtype')"; 
$r=mysql_query($q,$conn); 
if($r) 
{ 
    echo "Information stored successfully"; 
} 
else 
{ 
    echo mysql_error(); 
} 
?> 

如何解決?

+0

要在哪裏存儲圖像? – C2486

+0

也許這將有助於http://stackoverflow.com/questions/27591379/cant-upload-and-store-the-image-to-the-database-by-using-php –

回答

2

Typo。獲取MIME信息時使用錯誤的變量名稱。將$ image [mime]替換爲$ image_s; getimagesize()提供mime信息。

$image_s = getimagesize($_FILES['image']['tmp_name']); 
$imgtype = $image_s['mime']; 
相關問題