Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
File extension validation fails if you try to upload a file like 'fred.php' or 'jenny'. This seems to be because these types of files are automatically renamed for security purposes. This rename, stops the file extension validation from being called it seems.
public function buildForm(array $form, FormStateInterface $form_state) {
$form['document_scan'] = array
(
'#type' => 'managed_file',
'#title' => t('Document (Scanned Copy)'),
'#description' => t('Upload a file. Allowed extensions: pdf, jpg, jpeg, png, gif'),
'#required' => TRUE,
'#upload_validators' => array
(
'file_validate_extensions' => array('pdf jpg jpeg png gif'),
'file_validate_size' => array(25600000),
),
'#upload_location' => 'public://myfile/'
);
Comments
Comment #2
cilefen CreditAttribution: cilefen commentedI am not sure what this bug report means as written.
Comment #4
pameeela CreditAttribution: pameeela commentedGiven there has been no update since the original post and it isn't clear what this issue is about I'm going to close it.
If anyone can provide complete steps to reproduce the issue (starting from "Install Drupal core") in the issue summary and set the issue status back to "Active".
Thanks!