====== 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.
===== External App Settings =====
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.
===== Server Settings =====
* 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** ([[litespeed_wiki:php:run-without-timeouts|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** ( [[litespeed_wiki:config:envirnment_variables#wait-req-full-body|Learn more]])
===== PHP Testing Script =====
Here is a simple PHP upload script that you can use to test large file uploads.
";
echo "post max size: ".ini_get('post_max_size');
echo "
";
echo "max execution time : ".ini_get('max_execution_time');
echo "
";
echo "memory limit: ".ini_get('memory_limit');
echo "
";
echo "upload tmp dir: ".ini_get('upload_tmp_dir');
echo "
";
echo "
";
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);
}
}
?>
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.