Last updated December 6th, 2023 00:18
Are you using the WordPress content management system on your website? You probably know that for enhanced security reasons, it only allows uploading certain file types. These typically include files commonly used in computer work, such as images, documents, or videos. Unfortunately, any other less typical file formats are prohibited by default in WordPress and need to be manually enabled. If you have ever encountered the error message “Sorry You are not Allowed to Upload this File Type,” you are in the right place. Let’s take a look at how to handle it.
Sorry You are not Allowed to Upload this File Type
If you were to attempt adding any file format other than the allowed ones, WordPress would return this error message to you.
Therefore, let’s now demonstrate the procedure of allowing other file extensions for upload using the function.php file.
Editing the function.php file
Enabling file upload is done by modifying the function.php script, which is accessible through the editor of your theme. Since you will be directly modifying the source code of the theme template, it is strongly recommended to create a backup of the template itself or, at the very least, the entire code of the function.php script before proceeding with this step.
The importance of the function.php file is indisputable, as it is executed and its contents are interpreted every time WordPress is loaded. This file serves as a place where website creators can insert their own PHP code to customize various aspects of the website.
In the function.php file, you can define custom functions that extend the standard functionalities of WordPress. These functions can be used to add new features, manipulate content, change the appearance and behavior of the theme, or add new user roles. This allows for the creation of unique and specific websites that cater to individual requirements and needs.
The function.php file also enables the registration and configuration of plugins, ensuring the proper integration of external functionalities into WordPress. This may involve adding custom administrative pages, adjusting plugin settings, or implementing various actions and filters that affect the behavior and output of the website.
To modify the function.php script, follow these steps:
- Log in to your WordPress administration panel
- In the left-hand menu, click on “Appearance“
- Then, in the submenu, navigate to “Theme Editor“
- In the right-hand menu, select “function.php” from the list of template files.
- Insert the code provided below at the end of the script in the editor
- Click on “Update File” to save the changes.
The code that you need to insert into the function.php file is as follows:
function my_myme_types($mime_types){
$mime_types['svg'] = 'image/svg+xml'; //Povolí .svg
return $mime_types;
}
add_filter('upload_mimes', 'my_myme_types', 1, 1);
The line that will be of most interest to us is:
$mime_types['svg'] = 'image/svg+xml'; //Povolí .svg
In this line, you are defining the file extension. In our case, it is the .svg file, and you are also specifying its MIME type within the line.
This MIME type consists of two parts: the type and the subtype, separated by a slash. The type represents a general category of data, such as text, images, audio, or video. The subtype further specifies the specific format of data within that category.
For example, the MIME type for a regular text file in HTML format is "text/html," for an image in JPEG format it is "image/jpeg," and for an audio file in MP3 format it is "audio/mpeg."
In the [‘svg’] part of the code, you will insert the exact file extension of the file you want to allow for upload. Furthermore, after the equals sign, you need to insert the precise MIME type of the file. In our case, it is ‘image/svg+xml’.
If you don’t know the MIME type of your file, you can find it on a page like this: https://www.freeformatter.com/mime-types-list.html
How can I insert code to allow multiple files at once?
The principle is exactly the same as in the above case. You only insert each additional file on a new line. Let’s see an example:
function my_myme_types($mime_types){
$mime_types['svg'] = 'image/svg+xml'; // povolí .svg
$mime_types['psd'] = 'image/vnd.adobe.photoshop'; // povolí .psd
$mime_types['.abw'] = 'application/x-abiword'; // povolí .abw
return $mime_types;
}
add_filter('upload_mimes', 'my_myme_types', 1, 1);
As you can see, the code has changed only in that instead of one line with the allowed SVG file, we now have three lines. We have allowed not only the .svg file but also the .psd and .abw files.
Sorry You are not Allowed to Upload this File Type
Conclusion
In conclusion, it should be noted that WordPress does not have other files banned by default. Always consider carefully whether to allow additional file types or not. If it was meant to be a one-time file upload to the website, it might be better to upload such a file using FTP and not allow other file types in WordPress. After all, it partly concerns the security of the entire system. Keep this in mind at all times.
The website is created with care for the included information. I strive to provide high-quality and useful content that helps or inspires others. If you are satisfied with my work and would like to support me, you can do so through simple options.
Byl pro Vás tento článek užitečný?
Klikni na počet hvězd pro hlasování.
Průměrné hodnocení. 0 / 5. Počet hlasování: 0
Zatím nehodnoceno! Buďte první
Je mi líto, že pro Vás nebyl článek užitečný.
Jak mohu vylepšit článek?
Řekněte mi, jak jej mohu zlepšit.
Subscribe to the Newsletter
Stay informed! Join our newsletter subscription and be the first to receive the latest information directly to your email inbox. Follow updates, exclusive events, and inspiring content, all delivered straight to your email.