Large File Upload Failures

Many site applications allow users to upload files, and sometimes the files may be big, possibly 1GB or more. Such large uploads may fail if they are limited by server-level settings

If you are experiencing upload failures, here are some settings you can check.

Take a look at the following settings for external apps (typically PHP):

  • upload_max_filesize
  • post_max_size
  • max_execution_time - Some PHP scripts may need to do some post-upload processing, like resizing or watermarking, so max_execution_time could be a factor.
  • memory_limit
  • upload_tmp_dir - By default this would be /tmp. Many systems limit this directory to 2GB in size, which can be a problem if you upload a file bigger than 2GB. If your /tmp is too small and you cannot resize it, you can choose to change the location. For example, you could make it /var/tmp. This setting can not be overridden by .htaccess. It must be set in php.ini. Make sure the new directory has permission to allow the PHP user to read and write files. if you have open_basedir in action, the new path must be included there as well.
  • In Server Configuration > General, check Swapping Directory - This could be a problem for the same reason as PHP's upload_tmp_dir setting. You can change it to something like /var/tmp/lshttpd/swap, with default ownership and permission as shown:
    [root@test ~]# ls -l /tmp/lshttpd/ | grep swap
    drwxr-x--x 22 nobody nobody 4096 Aug 22 17:35 swap
  • In Server Configuration > Tuning, check Max Request Body Size (bytes)
  • External App Timeout (Learn more)
  • In External App, check Memory Soft Limit (bytes) and Memory Hard Limit (bytes). If you don't see PHP under External App, then go to the PHP tab instead, and raise to a number higher than the default 2047M. For testing purposes, you could blindly raise it to something like 20470M.
  • wait-req-full-body ( Learn more)

Here is a simple PHP upload script that you can use to test large file uploads.

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

echo "uplaod max size: ".ini_get('upload_max_filesize');
echo "<br>";
echo "post max size: ".ini_get('post_max_size');
echo "<br>";
echo "max execution time : ".ini_get('max_execution_time');
echo "<br>";
echo "memory limit: ".ini_get('memory_limit');
echo "<br>";
echo "upload tmp dir: ".ini_get('upload_tmp_dir');
echo "<br>";
echo "<br>";



   if(isset($_FILES['test'])){
      $errors= array();
      $file_name = $_FILES['test']['name'];
      $file_size =$_FILES['test']['size'];
      $file_tmp =$_FILES['test']['tmp_name'];
      $file_type=$_FILES['test']['type'];
      if (!file_exists('upload_test')) {
        mkdir('upload_test', 0777, true);
        }
      if(empty($errors)==true){
         move_uploaded_file($file_tmp,"upload_test/".$file_name);
         echo "Success";
      }else{
         print_r($errors);
      }
   }
?>
<html>
   <body>
      <form action="" method="POST" enctype="multipart/form-data">
         <input type="file" name="test" />
         <input type="submit"/>
      </form>
   </body>
</html>

This will simply determine if there is something wrong with PHP, LiteSpeed Web Server, or your site's application.

If this script works, but your site is still experiencing uploading problems, then there is probably something wrong in your site code.

  • Admin
  • Last modified: 2020/08/24 18:48
  • by Lisa Clarke