Reputation: 831
What's going on here? I have a a form that works precisely as intended for smaller files, yet as soon as I try uploading something larger, the form fails. I don't know what this size limit is, but it definitely doesn't work with a 40MB file.
Normal files return an error of 0, meaning they've uploaded successfully, but with large files, I don't even get an error. It's as if nothing in the form was passed through, and that includes the values of every other input in the form as well. There's something about large files that completely stops anything in the form from working.
I've already gone through my php.ini to make sure that the upload_max_filesize and post_max_size values are high enough, which they are (200M each). Since this server is local, and files I test are 'uploaded' instantaneously, but I've also made sure that max_execution_time is high enough as well (1200).
The form uses POST, the enctype is multipart/form-data, and I've already tried using a form that has nothing more than the file input and submit button.
This is the uploading code (ie, the code in the action page that the form redirects to):
<?php
require_once($_SERVER['DOCUMENT_ROOT'] . '/resources/recaptchalib.php');
$privatekey = "abc123";
$resp = recaptcha_check_answer($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
echo "<h1>" . $content['UploadError'] . "</h1>"
. $content['UploadCaptcha'] . "<br><br>"
. $content['UploadReturn'];
} else {
$name = $_POST['name'];
$email = $_POST['email'];
if (empty($name)) {
echo "<h1>" . $content['UploadError'] . "</h1>" .
$content['UploadName'] . "<br><br>" .
$content['UploadReturn'];
} elseif (empty($email)) {
echo "<h1>" . $content['UploadError'] . "</h1>"
. $content['UploadEmail'] . "<br><br>"
. $content['UploadReturn'];
} else {
$url = $_POST['url'];
$notes = $_POST['notes'];
$timedate = date('YmdHis');
$dbHandle = new PDO("mysql:host=localhost;dbname=upload;", "user", "pass",
array(PDO::ATTR_EMULATE_PREPARES => false));
$dbHandle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$query = $dbHandle->prepare("INSERT INTO `data` "
. "(approved,name,email,fileid,url,notes,timedate,viewcount) "
. "VALUES(?,?,?,?,?,?,?,?)");
$types = array(
'jpg', 'jpeg', 'gif', 'png',
'mp3', 'wma', 'wav', 'ogg', 'aac', 'flac',
'avi', 'wmv', 'mov', 'ogg', 'webm', 'mpg', 'mpeg', 'mp4'
);
$filechk = (isset($_FILES['file']) && !empty($_FILES['file']['name']));
$urlchk = (isset($url) && !empty($url));
if (!$filechk ^ $urlchk) {
echo "<h1>" . $content['UploadError'] . "</h1>"
. $content['UploadFileURL'] . "<br><br>"
. $content['UploadReturn'];
} elseif ($filechk) {
$filesize = (75 * 1024 * 1024);
$up_path = $_SERVER['DOCUMENT_ROOT'] . '/resources/uploads/';
$filename = $timedate . $_FILES['file']['name'];
$ex = explode(".", $filename);
$ext = strtolower(end($ex));
if (file_exists($up_path . $filename)) {
$filename = $timedate . 'Duplicate.' . $ext;
}
if (!in_array($ext, $types)) {
echo "<h1>" . $content['UploadError'] . "</h1>"
. $content['UploadFileType'] . "<br><br>"
. $content['UploadReturn'];
} elseif (filesize($_FILES['file']['tmp_name']) > $filesize) {
echo "<h1>" . $content['UploadError'] . "</h1>"
. $content['UploadFileSize'] . ($filesize / 1024 / 1024) . " MB<br><br>"
. $content['UploadReturn'];
} elseif (!is_writable($up_path)) {
echo "<h1>" . $content['UploadError'] . "</h1>"
. $content['UploadWriteError'] . "<br><br>"
. $content['UploadReturn'];
} elseif (move_uploaded_file($_FILES['file']['tmp_name'], $up_path . $filename)) {
$fileid = $filename;
$url = null;
$query->execute(array('N', $name, $email, $fileid, $url, $notes, $timedate, '0'));
echo "<h1>" . $content['UploadSuccess'] . "</h1>"
. $content['UploadHomepage'];
} else {
echo "<h1>" . $content['UploadUnknownError'] . "</h1>"
. $content['UploadReturn'];
}
} else {
$fileid = null;
$query->execute(array('N', $name, $email, $fileid, $url, $notes, $timedate, '0'));
echo "<h1>" . $content['UploadSuccess'] . "</h1>"
. $content['UploadHomepage'];
}
}
}
?>
var_dump($_FILES) results in array(0) { }
So my php.ini appears to be fine, my code appears to be fine (since I can upload smaller files)...What am I missing here?
Upvotes: 0
Views: 2228
Reputation: 7374
Have you changed the time limit the script can run for? It might be taking a while to process the large images and if the max timelimit isn't changed from the default (30 seconds usually) the script may well timeout. You can use:
ini_set('max_execution_time', [seconds]);
where seconds is the max number of seconds to wait before stopping the script.
Sorry, just noticed you've done this.
Is there anything in your error_log
?
Upvotes: 0
Reputation: 2016
Check the limits in your php.ini, there's more than one setting to look for -
upload_max_filesize = 64M
post_max_size = 64M
Make sure you restart apache for settings changes to take effect.
Upvotes: 2