Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

MIME Types

Name: Anonymous 2006-05-10 5:52

How do you use MIME Types in PHP, i mean, i want to use this to recognize whether i'm reading excel file or csv file

Name: Anonymous 2006-05-10 7:10

>>1
Depends;
- You mean the server reading some data, right?
- Is it reading it from a file?

If the answer to both of these questions is true, as I understand your post, you want to use the mime_content_type function from extension mime_magic. Check this out: http://php.net/mime_magic

That's assuming the file doesn't have a proper filename. If it does, then Excel files should be .XLS and CSV files should be .CSV, just case-insensitively detect the extensions.


If you mean detecting from file uploads sent by the client, you can use either $_FILES[field_id]['name'] for the filename or $_FILES[field_id]['type'] for the MIME type of the file; however, know that the browser may not send one of them or either of them, so I'd rely on type first, then name, then error. Google a bit for a list of MIME types where you can see what's the type for extensions .xls and .csv . For more information, check the PHP manual, section "Handling file uploads" or something like that.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List