views:

315

answers:

3

Hi friends,

This is one of the most bizarre errors I've come across. So I've written a little file upload web app for my friend and it works fine for any file less than or equal to 742kB in size. Needless to say, I arrived at this precise number based on relentless testing.

Weird part is that if the file size is just a few KB more, for example 743 or 750, I get an error saying "MySQL has gone away". But if it is 1MB or more, then I just get a blank screen. And it happens in less than 2 seconds after I hit the upload button. So it doesn't look like a time-out to me.

I checked out the PHP.ini file for post size and upload size, they are all set to 5 MB or more. And the timeout is set to 60 seconds.

The uploaded file sits in MySQL database in a field of datatype mediumblob. I tried changing that to longblob. But that didn't help either.

Any help?

Thanks for reading, Girish

+4  A: 

Try increasing max_allowed_packet (defaults to 1 mb) as described in the documentation here.

This link may also be of interest.

ChristopheD
Hi ChristopheD, max_allowed_packet is set to 2 MB, actually.
I just increased it to 32MB and it still didn't make any difference unfortunately.
+1  A: 

What is the mysql error number you are getting from the query to upload?

PHP Ref: mysql_error

Kris.Mitchell
Wow. Thanks for that tip. I didn't know I could get more details about the error like that. I tried it and here's what I got.A fatal MySQL error occured.Query: INSERT INTO uploadedfiles (name, size, type, content ) VALUES ('girish.xls', '760320', 'application/vnd.ms-excel', 'ÐÏࡱá\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0>\0\0þÿ \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0È\0\0\0\0\0þÿÿÿ\0\0\0\0\0\0\0\0b\0\0\0ã\0\0\0d\0\0å\0\0f\0\0ç\0\0h\0\0é\0\0j\0\0ë\0\0l\0\0ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ\0 \0\0\0 \0\0\0\0\0\0\0\0\0 \0.......Error: (2006) MySQL server has gone away
A: 

http://dev.mysql.com/doc/refman/5.0/en/packet-too-large.html

Danny Wilkerson
Like I mentioned earlier, I increased it to 32MB and it still didn't make any difference unfortunately.