So currently I am using a customized form that allows logged-in users to upload images. I am using the Wordpress media_handle_upload function to handle this task.
This function has always worked fine until recently. Users are able to upload images that are less than one megabyte. However when one attempts to upload larger images, the dreaded blank screen appears. No error messages are produced, even though I set the 'WP_DEBUG' to true in the config file.
I tested this for an image greater than 4 megabytes, and even though the blank screen subsequently appeared, the image was actually uploaded to the upload directory. I even checked the database and found an attachment record created for that image. My hosting platform is configured to handle large images, so I am at a loss for an explanation. Did anyone else experience a similar problem? Here’s the code:
function uploadGalleryImages($input_name)
{
$files = $_FILES[$input_name];
foreach ($files['name'] as $key => $value) {
$error = false;
if (trim($value) != '') {
/* Run tests for errors */
if ($files['error'][$key]) {
//return $_FILES[$input_name]['error'][$key];
$error = true;
}
$image_data = getimagesize($files['tmp_name'][$key]);
//Check for proper file types
if (!in_array($image_data['mime'], unserialize(TYPE_WHITELIST))) {
$error = true;
}
//Check if file exceeds max upload size, in this case 10 MB
if (($files['size'][$key] > MAX_UPLOAD_SIZE)) {
$error = true;
}
/* End of run tests for errors */
/* If no error, proceed to upload */
if (!$error) {
$file = array(
'name' => $files['name'][$key],
'type' => $files['type'][$key],
'tmp_name' => $files['tmp_name'][$key],
'error' => $files['error'][$key],
'size' => $files['size'][$key]
);
$_FILES = array("upload_file" => $file);
$attachment_id = media_handle_upload("upload_file", 0);
if (!is_wp_error($attachment_id)) {
//Success
} else {
//Failure
}
} else {
//Error messages
}
}
}// End foreach
return;
}