I have a file field with the following allowed file extensions: txt, pdf, doc, docx, zip
The Maximum upload size
is set via my php.ini and it is upload_max_filesize = 2M
1. While I'm trying to upload a file that exceeds the maximum file size I get the following error as expected:
Any other file (with
file_size < 2MB
) uploaded from before (form submit) remains as is and I have the ability to re-upload a new file.
I observed that this is working good with all types of files except one, the .pdf
type.
2. When I upload a file.pdf
with file_size > 2MB
I get this error:
All previous uploaded files (if any - with file_size < 2MB
) are disappearing (*) and I don't have the ability to re-upload a new file except if I refresh the page anew.
The expected behavior would was this (1.) :a warning message telling me about the size of the file and an option to re-upload a file without having to refresh the page anew. Instead I get (2.) an error message and no possibility to re-upload any files without refreshing the page.
Note that this is the case only for .pdf
files!
Debugging info:
(*) I found that the responsible function for this behavior is this: file_ajax_upload
Its if()
statement evaluates to true
if (empty($_POST['form_build_id']) || $form_build_id != $_POST['form_build_id']) {
// Invalid request.
drupal_set_message(t('An unrecoverable error occurred. The uploaded file likely exceeded the maximum file size (@size) that this server supports.', array('@size' => format_size(file_upload_max_size()))), 'error');
$commands = array();
$commands[] = ajax_command_replace(NULL, theme('status_messages'));
return array('#type' => 'ajax', '#commands' => $commands);
}
and the the form's markup is being replaced nicely!
Another more interesting thing that I found through the chrome's console, and I believe that it points to the correct direction, is this:
I tried the following code but it didn't work:
$form['field_name']['#attached'] = array(
'drupal_add_http_header' => array(
array('Content-Type', 'text/html; charset=utf-8')
);
Do you think that this is related to a configuration related to my environment or a bug ? How can I solve this issue ? Should I go after the MIME
type somehow ?
php.ini
file, but theupload_max_filesize
is not my issue, my issue is the different error handling of the.pdf
files against all other file types.