I like to use the following:
First I initiate an array of supported mime types:
$supportedTypes = array( 'application/pdf' );
Next I get my actual uploaded file type:
$fileType = $_FILES['type'][0]
Then I use wp_check_filetype()
to get the extension and mimetype: $fileArray = wp_check_filetype( basename( $_FILES['name'][0] ) );
Finally I run a conditional to make sure that the uploaded mimetype is in my supported array:
if( in_array( $fileArray['type'], $supportedTypes ) ) {
IF the conditional is true you can proceed with your upload, otherwise the file won’t upload and you can bail out.
Related Posts:
- Media files exist in upload folder but not showing up
- Set limit to media upload?
- How to upload SVG in WordPress 4.9.8?
- Use a separate custom table (not posts) to handle file upload data
- PNG with transparent background turns black when uploaded and resized
- WP 3.3 > Still no option to enable automatic image overwrites?
- Custom upload directory per CPT; when removed, file not deleted
- Modify featured image path to Amazon S3
- How to set an upload directory for each media type?
- How to get all files inserted (but not attached) to a post
- How to protect uploads in multisite if user is not logged in?
- uploading files to the uploads folder via ftp
- Modify the array of selected images in media modal
- How can I upload SVG images using the media uploader?
- Remove upload_files capability from a role but allow role to manage an avatar image
- 3.5 media manager add CSS / JS to new ‘tab’ iframe content
- post_id missing from the wp-admin file upload request
- http error when uploading media files
- How can I upload a csv file into WordPress?
- How to link to the image editor’s Edit Image function?
- Image uploading stuck on “crunching”
- HTTP Error when uploading mp4 video file
- Change the size of the image preview on the media edit page
- “upload_mimes” filter not working. Need to allow WOFF and WOFF2
- Whole bunch of errors on WP website – media upload, edit slugs, edit screen not working [closed]
- Add select field to media uploader that adds a class to the image
- Retroactively place uploaded media into -month, -year based folders?
- Can’t seem to upload a file to a custom directory
- wp.media add context
- Conditional add_filter for upload directory?
- Need to download uploaded binary file
- Insert Image automatically when upload finishes wordpress media uploader
- How do I modify the url of uploaded media content?
- WordPress “HTTP error.” when uploading Media – IIS
- Limit upload file type on one custom post type
- Uploading images on front end doesn’t generate thumbnail sizes
- Adding Media Upload to Custom Options Panel breaks “Insert into Post”
- WordPress bug with capabilities?
- media_handle_upload() progress bar
- Media Library does not show the uploaded image
- Attach Thumbnail Generated from Video Upload as Featured Image for the Video
- Manipulate CSV data during upload, is it possible?
- Check if uploaded file has a specific filename
- How to submit data between wp_iframe and backbone.js in media upload
- Uploading .mp3 files http error – 2 “exact” files one successful other fails
- HTTP Error after finishing uploading a video that is bigger than 64 MB -> After raising the upload limit manually in the wp-config file
- What are best practices to storing uploads in WordPress?
- Original image not saving?
- Restrict role to view own media
- Create featured image from a remote url when creating a post
- Image resizing – TimThumb vs convert on upload?
- File names are being overridden when uploading new media
- Patient portal using wordpress
- Change the look of the media uploader
- Issue with images which have no sizes available
- Is it safe to upload JSON files to upload folder?
- Unable to upload file more than 1MB in size
- WordPress media upload issue could not insert attachment into the database
- Thumbnail images missing in WP media library
- Upload media (image) and set the category
- Using Windows Server 2012 How to Move Uploads Folder to another hard drive
- get_attached_file returns wrong path after changing media upload dir
- How to adapt upload_dir to save files outside of WP uploads folder
- wp_generate_attachment_metadata for non-images files
- wp_enqueue_media() and upload_mimes problem
- Reattach media after moving to another server
- Upload a custom csv file, read contents and delete that file
- What if I have a large file on the server that I want the wp library to have?
- Limit image upload to 10
- Bug: Deleting file, then uploading same file again places file in an old month folder
- Can i add custom meta box (Media Uploader) at Category Description
- Complicated image name like flickr does and deny access just to original image
- Parsing the post title to the media box page
- Problems with uploading pictures to WordPress
- How to change Route respond To A specific Path?
- Where to store sensitive uploaded file?
- Media Library: Remove replace images of selected author
- how to change the max size of media upload? video audio wp 4.9.6
- How to upload multiple images using WP rest API to media?
- How to do action form from functions.php?
- Custom gallery displayin and sorting error
- Using WordPress’s add_cap method to Allow Contributors to Upload Media is not Working
- Import all media referenced in posts
- How use custom upload directories in filesystem and url based on media type or category
- Site Icon upload and display in a theme
- Include file upload button inside post and process file
- How to configure WordPress to create thumbnails
- My deleted media exists jet
- owner/group issue on server
- wordpress 3.6 media manager cropping timestamp
- Automatically adding images to a certain page through the Media Uploader
- Disable media upload in rich text editor
- WordPress shows different upload_max_filesize than php.ini setting
- Can’t upload files 1MB+ [closed]
- WordPress Custom Fonts Problem! [closed]
- I want to customize wp.media (the wordpress admin uploader) in order to change the file name but only in video custom post type
- Auto shortlink for file uploads
- Obtaining detailed error information from Media file upload process
- Is it possible to restrict the number of media uploads (photos) per user?
- How to restrict product access to personal user uploads in WordPress