Uploading Big Files

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ddtpmyra
    Contributor
    • Jun 2008
    • 333

    #1

    Uploading Big Files

    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[code=php]
    <?php
    # Check if a file has been uploaded
    if(isset($_FILE S['uploaded_file']))
    {
    # Make sure the file was sent without errors
    if($_FILES['uploaded_file']['error'] == 0)
    {
    # Connect to the database
    $dbLink = mysql_connect(" localhost","use r", "password")
    or die("Error! Failed to connect to the MySQL server!");
    mysql_select_db ("tablename" , $dbLink)
    or die("Error! Failed to select a database!");

    # Gather all required data
    $name = mysql_real_esca pe_string($_FIL ES['uploaded_file']['name'], $dbLink);
    $mime = mysql_real_esca pe_string($_FIL ES['uploaded_file']['type'], $dbLink);
    $size = $_FILES['uploaded_file']['size'];
    $author = $_POST['author'];
    $requestor = $_POST['requestor'];
    $description = $_POST['description'];
    $data = mysql_real_esca pe_string(file_ get_contents($_ FILES ['uploaded_file']['tmp_name']), $dbLink);

    # Create the SQL query
    $query = "
    INSERT INTO fileStorage (
    FileName, FileMime, FileSize, FileData, Created, Author,
    )
    VALUES (
    '{$name}', '{$mime}', {$size}, '{$data}', NOW(), '$author'
    )";

    # Execute the query
    $result = mysql_query($qu ery, $dbLink);

    # Check if it was successfull
    if($result)
    {
    echo "Success! Your file was successfully added!";
    echo "$author";
    }
    else
    {
    echo "Error! Failed to insert the file";
    echo "<pre>". mysql_error($db Link) ."</pre>";
    }
    }
    else
    {
    echo "Error!
    An error accured while the file was being uploaded.
    Error code: ". $_FILES['uploaded_file']['error'];
    }

    # Close the mysql connection
    mysql_close($db Link);
    }
    else
    {
    echo "Error! A file was not sent!";
    }

    # Echo a link back to the mail page
    echo '<p>Click <a href="cmr.php"> here</a> to go back</p>';
    ?>[/code]


    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_pa cket'
    Last edited by pbmods; Aug 20 '08, 11:28 PM. Reason: Added CODE tags.
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    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_file size directive in php.ini. "
    Meaning that to fix this problem, you would have to increase the upload_max_file size 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_pac ket directive in the my.cnf file on your server.

    Comment

    • ddtpmyra
      Contributor
      • Jun 2008
      • 333

      #3
      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=englis h
      bind-address=XX.XX.X X.X
      port=3306
      datadir=VOL3:/MySQL/Data
      skip-locking
      skip-innodb
      max_allowed_pac ket=25M


      PHP.INI
      ; Maximum size of POST data that PHP will accept.
      post_max_size = 25M
      ; Maximum allowed size for uploaded files.
      upload_max_file size = 25M

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        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.

        Comment

        • ddtpmyra
          Contributor
          • Jun 2008
          • 333

          #5
          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_pa cket';

          result:
          variable_name value
          max_allowed_pac ket 1048576

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

          MB

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            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.

            Comment

            • ddtpmyra
              Contributor
              • Jun 2008
              • 333

              #7
              Hi Atli,

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

              You rock!

              Comment

              Working...