CodeIgniter: Resolving the "Filetype Not Allowed" Upload Issue
In this CodeIgniter upload scenario, users face an error indicating that the attempted upload's file type is not permitted. Despite specifying the allowed file types in the controller, certain file formats, such as WMV videos, fail to upload.
During the upload process, CodeIgniter attempts to determine the file's MIME type. However, in some cases, Firefox or other browsers may incorrectly interpret the file extension as the MIME type. This can lead to the "filetype not allowed" error when the MIME type is not recognized in the configuration.
To resolve this issue, we can inspect the MIME type detected for the uploaded file by adding the following line to the controller's upload() method:
<code class="php">$this->_file_mime_type($_FILES[$field]); var_dump($this->file_type); die();</code>
After uploading a WMV file, it will display the detected MIME type. For example, it might show application/octet-stream, which is not included in the allowed MIME types configuration.
To solve the issue, add the detected MIME type to the mimes.php configuration file:
<code class="php">'wmv' => array('video/x-ms-wmv', 'audio/x-ms-wmv', 'application/octet-stream')</code>
By adding the correct MIME type to the configuration, CodeIgniter will recognize the WMV file type and allow its upload.
Note that browser or machine configuration can impact the upload behavior. For example, on certain systems, only AVI uploads may succeed, while on others, all supported files can be uploaded. This suggests that the problem may also be browser- or system-specific.
If the MIME type resolution approach does not resolve the upload issue, refer to the following resources for further troubleshooting:
The above is the detailed content of Why Does CodeIgniter Reject My WMV Files Even Though I Specified Allowed File Types?. For more information, please follow other related articles on the PHP Chinese website!