Skip to content

Commit 09b6261

Browse files
committed
Check the file type and extension before uploading a file.
1 parent be8913a commit 09b6261

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

includes/functions.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,11 @@ function wpum_upload_file( $file, $args = array() ) {
561561
return $file;
562562
}
563563

564+
$check = wp_check_filetype_and_ext( $file['tmp_name'], $file['name'] );
565+
if ( ! $check['ext'] || ! $check['type'] ) {
566+
return new WP_Error( 'upload', __( 'Sorry, you are not allowed to upload this file type.' ) );
567+
}
568+
564569
if ( ! in_array( $file['type'], $allowed_mime_types ) ) {
565570
if ( $args['file_label'] ) {
566571
return new WP_Error( 'upload', sprintf( __( '"%1$s" (filetype %2$s) needs to be one of the following file types: %3$s', 'wp-user-manager' ), $args['file_label'], $file['type'], implode( ', ', array_keys( $allowed_mime_types ) ) ) );

0 commit comments

Comments
 (0)