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

CatsFromStonehenge created an issue. See original summary.

cilefen’s picture

I am not sure what this bug report means as written.

Version: 8.2.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Branches prior to 8.8.x are not supported, and Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

pameeela’s picture

Status: Active » Closed (cannot reproduce)

Given 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!