I am writing a Unit Test for a class and need to generate a few files with different mime-types.
I know how to set the mime-type when sending a file to a remote user (ala header()
), but how to do it when using fwrite()
on the local server?
For a file generated in this method is the mime-type derived directly from the file extension?
I'm using PHP 5.3.x on Ubuntu 12.04
Files don't have mime types. They are identified by their file extensions. The mime types are usually set by file extensions in /etc/mime.types
. All the mime type does is tell the client what program to use to open the file.
mime-type usually makes sense for web browsers and email clients only NOT for your physical files. Just create your files with correct extensions and Ubuntu File Manager will interpret it accordingly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With