0

i am store image in database by using long blob.
here is my code for that

$file = isset($_FILES['fileupload']) ? $_FILES['fileupload']['tmp_name'] : false;
...
$query = mysql_query("Select * FROM image WHERE image_short_name = '$image_short_name_p' AND user_id='$id'");

$image = chunk_split(base64_encode(file_get_contents($_FILES['fileupload']['tmp_name'])));  
$image_width_height = getimagesize($_FILES['fileupload']['tmp_name']);

$insert = mysql_query("INSERT INTO image VALUES(NULL, '$user_id_db', '$image', 
                            '$image_full_name', '$image_short_name_p', '$image_des_p','' ,'$image_resolution',0, 0)"

it works fine but if i upload a really big image it get me error for ex.

Warning: mysql_query() [function.mysql-query]: MySQL server has gone away in C:\xampp\htdocs\a_upload\upload.php on line 59
Warning: mysql_query() [function.mysql-query]: Error reading result set's header in C:\xampp\htdocs\a_upload\upload.php on line 59
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\a_upload\upload.php on line 103

not sure how can i fix this problem.
i was think some thingk like this but i dont know how to do this

if(image size is bigger than long blob)
{
    reduce size so it fits
}

note i want to store in database and yes i know i should do it like that.

2
Contributors
8
Replies
9
Views
5 Years
Discussion Span
Last Post by diafol
1

InnoDB blobs can be up to around 4Gb - or so I believe. BUt I think it's dependent on the amount of data you can shift in one go as opposed to how much a field can store.

I'll have a look at the image thingy - back in a few.

0

right know my long blob store about size kb's.

by any change you know how can i increase the size?

1

Yes, same happened to me. Mind you, if you're using web images, they should be in Kb rather than Mb. As an user on limited bandwidth, I'd be a little annoyed with such a hefty image. My foreign mobile internet usage would be done in one page view!

0

ah i c so i should just check so if user upload a size mb file than i just resize it to kb? or some thing like that

0

so some thing like this

$file_size = filesize($file);
if($image_size <= 1073741824)  //image size is in mb's
{
   reduce size so it in kb's           //not sure how to do this part
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.