473,399 Members | 4,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Not able to upload a file above 1MB in my MYSQL database

This is an coding for uploading of word,pdf,and ppt file in an database. where as the file below 1Mb are stored in database but the file above 1mb show the below error........

Error........
Warning: mysql_query() [function.mysql-query]: MySQL server has gone away in C:\wamp\www\WORK CENTER\profile.php on line 21

Warning: mysql_query() [function.mysql-query]: Error reading result set's header in C:\wamp\www\WORK CENTER\profile.php on line 21

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.             // uploadAction.php
  3.             include('config.php');
  4.             if($_SERVER["REQUEST_METHOD"] == "POST")
  5.                 {
  6.                 if (($_FILES["form_data"]["type"] == "application/pdf")
  7.                     || ($_FILES["form_data"]["type"] == "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
  8.                     || ($_FILES["form_data"]["type"] == "application/msword")
  9.                     || ($_FILES["form_data"]["type"] == "application/vnd.openxmlformats-officedocument.presentationml.presentation")
  10.                     || ($_FILES["form_data"]["type"] == "application/vnd.ms-powerpoint"))
  11.                 {
  12.                 $id= mysql_insert_id(); 
  13.                 $file = $_FILES['form_data']['name'];
  14.                 $file_tmpName  = $_FILES['form_data']['tmp_name'];
  15.                 $file_size = $_FILES['form_data']['size'];
  16.                 $file_type = $_FILES['form_data']['type'];
  17.                 $file_section = $_POST["section"];
  18.                 $data=addslashes(fread(fopen($file_tmpName,"r"),filesize($file_tmpName)));
  19.  
  20.                         $queryUser = "INSERT INTO upload (id,data,name,size,type,section) VALUES('$id','$data','$file', '$file_size','$file_type','$file_section')";
  21.                     $insert = mysql_query($queryUser);
  22.  
  23.                         if(!$insert) 
  24.                         {
  25.                             echo "<div class='f_upload'>upload fail</div>";
  26.                         }
  27.                         else 
  28.                         {
  29.                             echo "<div class='f_upload'>file uploaded successfully</div>";
  30.                         }
  31.                 }  
  32.                 else
  33.                 {
  34.                  echo "<div class='f_upload'>Invalid file Plz check ur file</div>";
  35.                 }  
  36.             }
  37.         ?>
  38.  
Sep 4 '12 #1
1 3774
Atli
5,058 Expert 4TB
This is a configuration issue on the MySQL server. By default it only allows packets that are 1 MiB large. When using the old MySQL API to send files larger than that injected into the string, you need to adjust that setting to allow for larger packets.

See: C.5.2.10. Packet too large.


By the way, the method you are using to fetch the file data for your query is NOT the proper way to do that. When injecting binary data into a MySQL query, it must be passed through the mysql_real_escape_string function first. Otherwise the binary data may corrupt the query and cause it to fail. (And no, the addslashes function is not enough to prevent that, no matter what 10 year old post you copied that code from!)

Also, you can replace the whole fread(fopen($file_tmpName,"r"),filesize($file_tmpN ame) mess with the file_get_contents($file_tmpName) function.
Sep 4 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: rcb845 | last post by:
Hi everybody in the php community, I am relatively new in this field, and one of my first challenge is the following : Importing an Excel file, containings URL, into a MySQL database. It...
0
by: ramaraog80 | last post by:
Hi, I need a VB Script which exports data from CSV file to MySql Database Regards Ramarao G
0
by: goldwingers | last post by:
Have a large 153400 KB MySql database to upload and have to break it up into 2048KB pieces and upload it thru the MySql admin 1 piece at a time. Is there any software that can speed up breaking the...
6
by: nagaraj530 | last post by:
hi friends, i want to store a video file in mysql database, if u r having any related code, please give me reply, i am waiting for that
21
by: ding | last post by:
I am facing problem to writting file to MySQL database in java application. Can show me a example code? Thanks!
4
by: grouchy | last post by:
hello all, not sure if i fully explained myself on an earlier post. All i really need to do is to store an xml file into mysql database. I have no idea how to do this, including any php code i...
2
by: wingleader | last post by:
Hi! I'm looking for ways of uploading image file to mysql database. I know, that it should be possible, but don't know how to do it.... could someone help me?
2
by: vineya | last post by:
Would you kindly help me in loading csv file into mysql database.
8
by: jessica87 | last post by:
hi there.... i need some guidance here with this code? Code: ( text ) 1. $myFile = "testFile.txt"; 2. $fh = fopen($myFile, 'w') or die("can't open file");
2
by: jitendrawel | last post by:
how can be import excel file in mysql database through PHP code. Please send me complete code ASAP. Thanks. Best regards, Jitendra Kumar
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.