1. Home
  2. Knowledge Base
  3. WooCommerce Product Add-Ons Ultimate
  4. Field Types
  5. File Uploads
  6. Only allow uploads for one file type
  1. Home
  2. Knowledge Base
  3. WooCommerce Product Add-Ons Ultimate
  4. Only allow uploads for one file type

Only allow uploads for one file type

Let’s say you only want to allow one file type to be uploaded. Here’s an example of how to ensure users can only upload zip files (but you can amend this for any file type).

<?php
// Set the list of permitted mime types to zip only
function prefix_only_permit_zip( $permitted_mimes ) {
$permitted_mimes = array( 'zip' => "application/zip" );
return $permitted_mimes;
}
add_filter( 'pewc_permitted_mimes', 'prefix_only_permit_zip' );
// Add PDF to the list of restricted filetypes
function prefix_protected_directory_zip_only( $restricted_filetypes ) {
$restricted_filetypes = array( 'zip' );
return $restricted_filetypes;
}
add_filter( 'pewc_protected_directory_allowed_filetypes', 'prefix_protected_directory_zip_only' );

Here’s how to add a snippet.

Was this article helpful?

Related Articles