By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,747 Members | 2,039 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,747 IT Pros & Developers. It's quick & easy.

Uploading Big Files

ddtpmyra
100+
P: 333
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
Share this Question
Share on Google+
6 Replies


Atli
Expert 5K+
P: 5,058
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
100+
P: 333
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
Expert 5K+
P: 5,058
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
100+
P: 333
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
Expert 5K+
P: 5,058
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
100+
P: 333
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

Post your reply

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