473,398 Members | 2,368 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,398 software developers and data experts.

Uploading Big Files

ddtpmyra
333 100+
Problem
I got this cool tool from 'Howtos' posted by ATLI, but I'm having trouble on posting or uploading files bigger than 15000KB although I create the table field into a 'LongBlob'. Is there any other way to maximize the the field?

Script
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. # Check if a file has been uploaded
  3. if(isset($_FILES['uploaded_file']))
  4. {
  5.     # Make sure the file was sent without errors
  6.     if($_FILES['uploaded_file']['error'] == 0)
  7.     {
  8.         # Connect to the database
  9.         $dbLink = mysql_connect("localhost","user", "password")
  10.             or die("Error! Failed to connect to the MySQL server!");
  11.         mysql_select_db("tablename", $dbLink)
  12.             or die("Error! Failed to select a database!");
  13.  
  14.         # Gather all required data
  15.         $name = mysql_real_escape_string($_FILES['uploaded_file']['name'], $dbLink);
  16.         $mime = mysql_real_escape_string($_FILES['uploaded_file']['type'], $dbLink);
  17.         $size = $_FILES['uploaded_file']['size'];
  18.         $author = $_POST['author'];
  19.         $requestor = $_POST['requestor'];
  20.         $description = $_POST['description'];
  21.         $data = mysql_real_escape_string(file_get_contents($_FILES  ['uploaded_file']['tmp_name']), $dbLink);
  22.  
  23.         # Create the SQL query
  24.         $query = "
  25.             INSERT INTO fileStorage (
  26.                 FileName, FileMime, FileSize, FileData, Created, Author,
  27.             )
  28.             VALUES (
  29.                 '{$name}', '{$mime}', {$size}, '{$data}', NOW(), '$author'
  30.             )";
  31.  
  32.         # Execute the query
  33.         $result = mysql_query($query, $dbLink);
  34.  
  35.         # Check if it was successfull
  36.         if($result)
  37.         {
  38.             echo "Success! Your file was successfully added!";
  39.             echo "$author";
  40.         }
  41.         else
  42.         {
  43.             echo "Error! Failed to insert the file";
  44.             echo "<pre>". mysql_error($dbLink) ."</pre>";
  45.         }
  46.     }
  47.     else
  48.     {
  49.         echo "Error!
  50.                 An error accured while the file was being uploaded.
  51.                 Error code: ". $_FILES['uploaded_file']['error'];
  52.     }
  53.  
  54.     # Close the mysql connection
  55.     mysql_close($dbLink);
  56. }
  57. else
  58. {
  59.     echo "Error! A file was not sent!";
  60. }
  61.  
  62. # Echo a link back to the mail page
  63. echo '<p>Click <a href="cmr.php">here</a> to go back</p>';
  64. ?>

Result
Error! An error accured while the file was being uploaded. Error code: 1
or
Error! Failed to insert the file
Got a packet bigger than 'max_allowed_packet'
Aug 20 '08 #1
6 3044
Atli
5,058 Expert 4TB
Hi.

The first error there would indicate a problem with your PHP configuration.
The error codes for file uploads are explained here.

Error code 1 means "The uploaded file exceeds the upload_max_filesize directive in php.ini. "
Meaning that to fix this problem, you would have to increase the upload_max_filesize directive. (You may also want to take a look at the post_max_size directive).

The second error you posted would probably be a problem with your MySQL configuration. I would start by changing the max_allowed_packet directive in the my.cnf file on your server.
Aug 27 '08 #2
ddtpmyra
333 100+
Hi Atli,

Still I'm having same problem although I adjusted the php.in and my.cnf below and by the way I'm running my mysql server on a novell box.

my.cnf
[client]
user=root

[mysqld]
default-character-set=latin1
language=english
bind-address=XX.XX.XX.X
port=3306
datadir=VOL3:/MySQL/Data
skip-locking
skip-innodb
max_allowed_packet=25M


PHP.INI
; Maximum size of POST data that PHP will accept.
post_max_size = 25M
; Maximum allowed size for uploaded files.
upload_max_filesize = 25M
Aug 28 '08 #3
Atli
5,058 Expert 4TB
That's weird.
Using those config files, neither of those error should appear.

Did you restart Apache after the changes?
Don't know Novell very well, but you could also try rebooting the server.

Is it possible that you are editing the wrong php.ini file? (I've done that a couple of times myself)
Take a look at the file indicated in the phpinfo() output, see if they match.
Aug 28 '08 #4
ddtpmyra
333 100+
Hi Atli,

Looks like my.cnf file didn't read at all when I view this command inside mysql

command:

show variables like 'max_allowed_packet';

result:
variable_name value
max_allowed_packet 1048576

questions
my.cnf file is located under etc folder where it should be lying?

MB
Aug 28 '08 #5
Atli
5,058 Expert 4TB
On my Ubuntu server the my.cnf file is under /etc/mysql/, although that may well be different for you.

Make sure you restart the mysql server to after editing the file.
Aug 28 '08 #6
ddtpmyra
333 100+
Hi Atli,

You were right it's all about restarting the novell box not just re-starting the apache and mysql.

You rock!
Aug 29 '08 #7

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

Similar topics

4
by: dickiedyce | last post by:
Hi there. I've spent the weekend getting ever more frustrated, trying to get an upload file function working on a website. The site is hosted by a company called oneandone. They're using PHP...
5
by: Kevin Ollivier | last post by:
Hi all, I've come across a problem that has me stumped, and I thought I'd send a message to the gurus to see if this makes sense to anyone else. =) Basically, I'm trying to upload a series of...
5
by: Ron Brennan | last post by:
Good afternoon. The entire task that I'm trying to achieve is to allow a user to browse and upload multiple files simultaneously, hiding the Browse button of <input> tags of type="file" and...
13
by: Sky Sigal | last post by:
I have created an IHttpHandler that waits for uploads as attachments for a webmail interface, and saves it to a directory that is defined in config.xml. My question is the following: assuming...
0
by: Raj | last post by:
Hello, I am planning to provide the Pause/Resume while uploading files. Our site is using both java applet and activex to do this. The list of selected files will be stored in an encrypted...
221
Atli
by: Atli | last post by:
You may be wondering why you would want to put your files “into” the database, rather than just onto the file-system. Well, most of the time, you wouldn’t. In situations where your PHP application...
2
by: =?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?= | last post by:
jodleren escribió: I haven't found the PHP manual page where such feature is documented but a few tests have shown that this behaviour changes depending on the charset parameter of the...
1
by: =?Utf-8?B?RGFu?= | last post by:
MS won't seem to let me reply to my old post, so I created a new one. The error occurs in all browsers. It's definitely a server issue, not client. The server is not proxied in any way. I tried...
3
by: muziburrehaman | last post by:
i am looking for code in php to upload the 1 gb files. any one can please help me by sending the code....
0
by: LoriFranklin | last post by:
I'm a bit of a newbie here. I've learned a lot from reading the posts you all have here. I need some help uploading files using an asp form. I am using some code that I found from Jacob at...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...

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.