Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a mime type on a file with php?

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

like image 950
Patrick Avatar asked Feb 05 '13 21:02

Patrick


2 Answers

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.

like image 178
Rob Avatar answered Sep 20 '22 07:09

Rob


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.

like image 44
anubhava Avatar answered Sep 19 '22 07:09

anubhava