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.

Member Avatar for diafol

How big are the images?

1920x1080 3.39mb get me error

i think i long blob limit size is only in kb's

Member Avatar for diafol

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.

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

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

Member Avatar for diafol

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!

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

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
}
Member Avatar for diafol

Few ways to do it - you could put the onus on the user to cut down the size of their image or DIY with some GD library functions.

AN example here:

http://www.white-hat-web-design.co.uk/blog/resizing-images-with-php/

I'm not endorsing this as a good example, just pointing out that there are many scripts out there specifically for this purpose. Have a look around.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.