Modify and add the problem that WP upload file type failed to upload

Lao Yang seven hundred and twenty-six zero

The default configuration of WP supports some common file types, but some file types that are not set by default cannot be uploaded. We can configure to allow uploading the file types we need to upload.

I will test and upload the ZB plug-in package. zba. PHP uploads files to get the. zba file type is application/octet stream,

Then add WP theme or plug-in

 add_filter('upload_mimes', 'custom_upload_mimes'); function custom_upload_mimes($existing_mimes=array()) { //Add file types that support uploading $existing_mimes['zba']='application/octet-stream'; return $existing_mimes; }

Uploading. zbp again or failed: Sorry, you have no right to upload this file type.

Then check the WP source code and find that if you enable the fileinfo extension in PHP, you will re read the file type of the temporary file $file

 $finfo     = finfo_open( FILEINFO_MIME_TYPE ); $real_mime = finfo_file( $finfo, $file ); finfo_close( $finfo );

Then the. zba file type is: application/xml. Knowing the real file type will solve the problem. Change the above code and you can upload the. zba file normally.

 add_filter('upload_mimes', 'custom_upload_mimes'); function custom_upload_mimes($existing_mimes=array()) { //Add file types that support uploading $existing_mimes['zba']='application/xml'; return $existing_mimes; }

 1. Modify and add the problem that WP upload file type failed to upload - Laoyang plug-in

The test found that if PHP does not support fileinfo, this configuration is very simple, $existing_mimes ['zba ']='1'; As long as the correct file suffix is set and the file type is set at will, the file can be uploaded normally.


Export Document
Reward the author
"Modifying and Adding WP Uploading File Types Failed to Upload". doc
Download and save this article for collection and printing
Export Document