I'm using a PHP script to upload doc/docx/pdf to my server. As long as the file size isn't bigger than 1MB, I don't have any issues with the upload, however the moment it's around 1MB, it just won't upload at all.
I updated the values in my .htaccess to the following:
php_value upload_max_filesize 10M
php_value post_max_size 10M
php_value max_input_time 300
php_value max_execution_time 300
php_value memory_limit 96M
There are no errors or warnings in the log file. I'm using the below code to upload the files:
$checkUpload = $_FILES["fileToUpload"]["name"];
$target_dir = realpath(dirname(__FILE__)) . "/uploads/";
$temp = explode(".", $_FILES["fileToUpload"]["name"]);
$newfilename = 'newfilename' . end($temp);
$target_file = $target_dir . $newfilename;
$uploadOk = 1;
$imageFileType = pathinfo($target_file, PATHINFO_EXTENSION);
if ($_FILES["fileToUpload"]["size"] > 500000) {
$uploadOk = 0;
}
if (($imageFileType != "pdf") && ($imageFileType != "doc") && ($imageFileType != "docx")) {
echo "wrong format!";
die();
}
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_dir . $newfilename)) {
} else {
echo "Sorry, there was an error uploading your file.";
}
}
I have restarted the apache after updates and checked the max size with the below script:
$max_upload = (int)(ini_get('upload_max_filesize'));
$max_post = (int)(ini_get('post_max_size'));
$memory_limit = (int)(ini_get('memory_limit'));
$upload_mb = min($max_upload, $max_post, $memory_limit);
echo $upload_mb;
The above confirms maximum size is 10M. I'm not even looking into uploading more than 5MB and can't figure out what the issue is.
E: I changed the values in php.ini, but it still doesn't work. I'm using PHP 7.0 with apache 2.4 on debian 8.
E2: I tried to upload the files using a WordPress plugin (Caldera Forms) and after a few battles this seems to be getting through to regular uploads folder (even with 4MB files). The issue is, I don't think using a plugin is a solution and I'd like to understand why I can't do it my way.
I'm currently getting the following warning:
PHP Warning: move_uploaded_file(): Unable to move '/tmp/phpThmBZJ' to '/var/www/mywebsite.com/uploads/form_uploads/1234.doc' in /var/www/mywebsite.com/public_html/wp-content/themes/mytheme/add_file.php on line 85, referer: http://mywebsite.com/
It would suggest a permission issue, but:
- the caldera form files are still getting through
- I made sure the apache is currently the owner of www and the relevant uploads folder
- upload folder permissions are set to 755
Update: since I started receiving the above warning, I can't even upload the small files anymore.
Thanks for help, E.