简体   繁体   中英

Blob datatype Image not stored in database

I am trying to store the image in database using the blob datatype.

but my program was not storing the image in database.

code:

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:

<?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. If you need more consider using a MEDIUMBLOB for 16777215 bytes or a LONGBLOB for 4294967295 bytes .

Look at Storage Requirements for String Types .

My suggestion is use LONGBLOB instead of 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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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