[英]I want to display "No Image" when there's no image 'BLOB' at MySQL database
[英]I want to store image on mysql database as blob type by php
我想通過php將圖像存儲在mysql數據庫上作為blob類型,但是顯示以下錯誤:
警告:getimagesize(3272)[function.getimagesize]:無法打開流:第15行的F:\\ XAMPP \\ htdocs \\ 0412 \\ form.php中沒有此類文件或目錄
我使用以下代碼:
if($_POST['upload'] == 'upload' ) {
// connect to database
mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("image") or die(mysql_error());
// name of the upload image
$name = addslashes($_FILES['uploadImage']['name']);
// image
$image = addslashes( file_get_contents( $_FILES['uploadImage']['tmp_name']) );
$size = getimagesize($_FILES['uploadImage']['size']);
if( $size == FALSE ) {
echo "NO image selected $form";
}
else {
move_uploaded_file($_FILES['uploadImage']['tmp_name'],"UploadImage/".$name);
if( !( $result = mysql_query(" INSERT INTO image VALUES ('','$name','$image') ") ) ) {
echo "uploading image problem $form";
}
}
這行:
$size = getimagesize($_FILES['uploadImage']['size']);
需要是:
$size = getimagesize($_FILES['uploadImage']['tmp_name']);
代替。 您getimagesize()
感到以下事實: getimagesize()
從圖像數據本身獲取圖像的大小。 您傳遞給它的是一個數字,指示它的上傳大小(以字節為單位)。
上面正確的示例從圖像的臨時位置打開該圖像,該圖像位於tmp_name
。
只需使用以下代碼::
if($_POST['upload'] == 'upload' ) {
mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("image") or die(mysql_error());
$name = addslashes($_FILES['uploadImage']['name']);
$image = file_get_contents( $_FILES['uploadImage']['tmp_name']) ;
if( !( $result = mysql_query(" INSERT INTO image VALUES ('','$name','$image')") ) ) echo "uploading image problem $form";
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.