简体   繁体   English

Blob数据类型图像未存储在数据库中

[英]Blob datatype Image not stored in database

I am trying to store the image in database using the blob datatype. 我正在尝试使用Blob数据类型将图像存储在数据库中。

but my program was not storing the image in database. 但是我的程序没有将图像存储在数据库中。

code: 码:

form.php: form.php的:

<form action="upload.php" method="post" enctype="multipart/form-data">
 File Name<input type="file" name="image" /><br />
 <input type="submit"  value="Upload" />
</form>

upload.php: upload.php的:

<?php
require_once('connection.php');

if(isset($_POST['submit'])){
    $image  =   addslashes(file_get_contents($_FILES[image]['tmp_name']));
    $query  =   "INSERT INTO images ('image') VALUES('".$image."')";
    mysql_query($query) or die(mysql_error());
    echo "Image id is ".mysql_insert_id();
    echo "Image id is ".mysql_insert_id();
}
?>

please resolve my problem.. 请解决我的问题..

A BLOB can store 65535 bytes maximum. BLOB最多可以存储65535 bytes If you need more consider using a MEDIUMBLOB for 16777215 bytes or a LONGBLOB for 4294967295 bytes . 如果需要更多,请考虑将MEDIUMBLOB用于16777215 bytes或者将LONGBLOB用于4294967295 bytes

Look at Storage Requirements for String Types . 查看字符串类型的存储要求

My suggestion is use LONGBLOB instead of BLOB. 我的建议是使用LONGBLOB代替BLOB。 Hope it will works. 希望它能起作用。

try to use the below code. 尝试使用下面的代码。

    $image  =   addslashes(file_get_contents($_FILES['image']['tmp_name']));
    $query  =   "INSERT INTO images (image) VALUES('".$image."')";

i think this time its work fine... 我认为这一次工作很好...

尝试在fieldName上使用反引号

$image  =   addslashes(file_get_contents($_FILES['image']['tmp_name']));

try this one.this is also another approach for storing the blob image. 试试这个。这也是另一种存储斑点图像的方法。

code: 码:

    $image= $_FILES["image"];
    $image= mysql_real_escape_string("$image");
    $query = "INSERT INTO images (image) VALUES('".$image."')";
    mysql_query($query) or die(mysql_error());
    echo "Image id is ".mysql_insert_id();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM