• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 382
  • Last Modified:

Large file uploads with PHP application

Hi Experts,

I run a small helpdesk service for my clients using a PHP help desk application called HelpSpot (http://www.helpspot.com).  It works very nicely and I rarely have any issues.  I am trying to configure the server to allow large files to be attached (ie: uploaded) to cases/requests.  HelpSpot has some guidelines on enabling large file uploads here: http://www.helpspot.com/helpdesk/index.php?pg=kb.page&id=34.  Based on their guidelines as well as other information I have found on the web, my PHP settings are as follows:

file_uploads = On
upload_tmp_dir = /tmp
upload_max_filesize = 10M
post_max_size = 20M
memory_limit = 128M
max_input_time = 360
max_execution_time = 360

In the MySQL config, max_allowed_packet is set to 33554432 (32 MB).

The problem is that I can successfully attach a 2 MB file to a case but I can't attach anything larger than 2 MB.  

I should mention that when a file is attached to a case it is not saved on the file system - it is saved in the MySQL database as a BLOB.  Also, the server OS is Ubuntu Server 8.04 LTS, and the versions of the various servers/packages are:

Apache:  2.2.8
PHP:  5.2.4-2ubuntu5.9
MySQL:  5.0.51

I have two questions:

1.  Is there anything wrong with the settings above or is there a setting I have overlooked?
2.  Is there a log file I can check to try and troubleshoot this issue?

Cheers,

Paul
0
mrgordonz
Asked:
mrgordonz
4 Solutions
 
domdornCommented:
Try increasing the max_allowed_packet size and see if you can upload bigger files. It may be, that the input data is encoded during the upload and is a lot bigger than just the raw filesize.

If you code the fileUpload yourself, you may consider to store the file in the filesystem and just store a reference to the file (path to the file) in the database, which is far more performant, especially for large files as it saves a lot of roundtrips from the webserver to the database when downloading the file again.

If you ever happen to switch the database, e.g. to PostgreSQL, check out their Large Object support.
0
 
Monis MontherSystem ArchitectCommented:
Try making all your php and Mysql parameters consistent 32MB

try the following

upload_max_filesize = 32M
post_max_size = 32M

Dont forget to restart httpd for this to work
0
 
mrgordonzAuthor Commented:
There is a setting in HelpSpot which lets you switch where attachments are saved from the database to file system.  I tried setting it to use the file system, but it made no difference - I can upload a 2 MB file, but not a 4 MB file.  I even updated the PHP settings to make

upload_max_filesize = 32M
post_max_size = 48M  (I made this bigger because I have read elsewhere that the post_max_size needs to be bigger than the actual file being uploaded).

The fact that it behaves the same even when saving attachments on the file system makes me think that it has nothing to do with the database (ie:  max_allowed_packet).

Is there a log file for which would help diagnose the problem.

Cheers,

Paul
0
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 
Ray PaseurCommented:
Look out for the "suhosin" hardened PHP thing.  If your hosting company installs this it can screw up your forms and ability to do large file uploads.

In PHP, there is something you need to put into the <form> to set upload sizes.  Check the MAX_FILE_SIZE data in this example.

HTH, ~Ray
<h2>Upload <?php echo $nf; ?> file(s)</h2>

    <!--
        SOME THINGS TO NOTE ABOUT THIS FORM...
        NOTE THE CHOICE OF ENCTYPE IN THE HTML FORM STATEMENT
        MAX_FILE_SIZE MUST PRECEDE THE FILE INPUT FIELD
        INPUT NAME= IN TYPE=FILE DETERMINES THE NAME YOU FIND IN $_FILES ARRAY
    -->

    <form name="UploadForm" enctype="multipart/form-data" action="<?=$_SERVER["REQUEST_URI"]?>" method="POST">
    <input type="hidden" name="MAX_FILE_SIZE" value="<?=$max_file_size?>" />
    <p>
    Find the file(s) you want to upload and click the "Upload" button below.
    </p>

    <?php for ($n = 0; $n < $nf; $n++)
        {
            echo "<input name=\"userfile$n\" type=\"file\" size=\"80\" /><br/>\n";
        }
    ?>
    <br/>Check this box <input autocomplete="off" type="checkbox" name="overwrite" /> to <b>overwrite</b> existing files.
    <input type="submit" name="_submit" value="Upload" />
    </form>

Open in new window

0
 
martinewskiCommented:
Did you restart Apache after changing the php variables?
Are you sure you're changing the right php.ini file? Maybe you should create a php script to show the phpinfo and check if those variables you have changed are in effect.

<?php
phpinfo();
?>

Open in new window

0
 
mrgordonzAuthor Commented:
Problem solved.  Turns out that there was a setting hidden deep in HelpSpot that limited the size of attachments.  That alone wasn't the problem though - I also needed to increase the max attachment size setting in Postfix.  Thanks to all who made suggestions.  Given that none of the comments actually solved the problem, but you were all kind enough to try and help, I will split the points evenly.

Cheers,

Paul
0
 
mrgordonzAuthor Commented:
Given that none of the comments actually solved the problem, but you were all kind enough to try and help, I will split the points evenly.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now