2

i have written a php code to upload .pdf file into my datbase. the code is working perfect for all pdfs which are less than 1 mb in size.but whenever i am trying to upload a file larger than 1 mb in size , it's failing to upload and throwing a error mysql server has gone away.

NOTE:: i have changed my php.ini with following changes

post_max_size=128M
upload_max_filesize=128M
memory_limit = 128M
max_execution_time = 300
max_input_time = 300

but it's not solving my problem.the problem remains same "it's failing to upload and throwing a error mysql server has gone away." MY PHP CODE IS ::

if(isset( $_POST['save']) and $_POST['save'] == "save")
{
  ini_set('default_socket_timeout', 1500);
  include_once $_SERVER['DOCUMENT_ROOT'].'/include/db.inc.php' ;
  if (!is_uploaded_file($_FILES['upload']['tmp_name']))
  {
    echo 'There was no file uploaded!';
    exit();
  }
  /*NOW I HAVE WRITTEN THE PHP CODE TO INSERT THE FILE INTO MY DATABASE.WHAT I CAN
  ASSURE YOU THIS PART IS PERFECT BECAUSE THE CODE IS SUCESSFUL ALL OTHER CASES
  WHICH ARE LESS THAN 1 MB IN SIZE*/

NOTE:: i also used a reconnect while sending the query.so there is not a connection problem

EDIT there is nothing like max_allowed_packet in my my.ini

Ritabrata Gautam
  • 3,093
  • 1
  • 31
  • 43

2 Answers2

8

I believe you also have to configure the MySQL server (my.ini on Windows) make sure there is:

[mysqld]
    max_allowed_packet=16M

in there - or any sufficiently high number

also note the same problem solved here: how to change max allowed packet size

Community
  • 1
  • 1
Martina
  • 1,624
  • 1
  • 10
  • 6
  • 1
    @RitabrataGautam As it is a problem regarding MySQL settings i would say it should be sufficient to restart only the MySQL server – Martina Mar 15 '13 at 14:11
  • i am sorry..i have very few knowledge regarding mysql..can u advise me how to restart mysql server – Ritabrata Gautam Mar 15 '13 at 14:13
  • 1
    @RitabrataGautam Assuming you are on Windows XP, go to Control panel / Administrative Tools / Services. There locate the MySQL service in the list and chose to "restart" - or - if you can not find it, after changing the my.ini file restart your computer - the service will restart with it :) – Martina Mar 15 '13 at 14:15
  • now what i am going to say is bery surprising.in my "my.ini"..there is nothing like `max_allowed_packet` .... ican't find it – Ritabrata Gautam Mar 15 '13 at 14:23
  • 1
    @RitabrataGautam : That is not surprising at all. That only means mysql is using the default value of 1M - You will need to insert the line max_allowed_packet=16M somewhere into the my.ini file UNDER the section of [mysqld]. Also make sure you do the change in that my.ini file that counts (there may be several copies of it on your harddrive) – Martina Mar 15 '13 at 14:26
  • thanks ,thanks and thanks..am literally grateful to u..it was a pain in the neck..solved it..lots of thanks sister – Ritabrata Gautam Mar 15 '13 at 14:37
  • @RitabrataGautam happy to help :) – Martina Mar 15 '13 at 14:38
0

There are quite a few things that can cause this, you can get a good overview here: http://dev.mysql.com/doc/refman/5.1/en/gone-away.html

You can start by trying this:

ini_set('mysql.connect_timeout', 300);
ini_set('default_socket_timeout', 300);
zajd
  • 761
  • 1
  • 5
  • 18