Support

Account

Home Forums Bug Reports Upload validation prevents uppercase filetype

Solved

Upload validation prevents uppercase filetype

  • In 5.2.8, if upload file type validation logic is added, uppercase file types are not supported. For instance, it would be impossible to upload my-image.JPG. To replicate it:

    1. Add an image/gallery/file field
    2. For “Allowed File Types”, insert “JPG” (or “jpg, JPG”)
    3. Try uploading a JPG image with an uppercase file extension
    4. An error message occurs: “File type must be jpg”

  • Hi @crabilld

    Thanks for the bug report.

    I’ve just found and fixed the issue.
    Can you please edit the api/api-helpers.php file on line 3224 and change the if statement to:

    
    // file type
    	if( $file['type'] ) {
    		
    		$mime_types = acf_maybe_get($field, 'mime_types', '');
    		
    		// lower case
    		$file['type'] = strtolower($file['type']);
    		$mime_types = strtolower($mime_types);
    		
    		
    		// explode
    		$mime_types = str_replace(array(' ', '.'), '', $mime_types);
    		$mime_types = explode(',', $mime_types); // split pieces
    		$mime_types = array_filter($mime_types); // remove empty pieces
    		
    		if( !empty($mime_types) && !in_array($file['type'], $mime_types) ) {
    			
    			// glue together last 2 types
    			if( count($mime_types) > 1 ) {
    				
    				$last1 = array_pop($mime_types);
    				$last2 = array_pop($mime_types);
    				
    				$mime_types[] = $last2 . ' ' . __('or', 'acf') . ' ' . $last1;
    				
    			}
    			
    			$errors['mime_types'] = sprintf(__('File type must be %s.', 'acf'), implode(', ', $mime_types) );
    			
    		}
    				
    	}
    

    This should allow uppercase file extensions to validate correctly.

    Thanks
    E

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Upload validation prevents uppercase filetype’ is closed to new replies.