Canman2005 Posted May 27, 2007 Share Posted May 27, 2007 Hi all I have a simple file upload script. but I want to capture and store the files mime type. What is the easiest way to do this? Any help would be great Thanks in advance Ed Link to comment https://forums.phpfreaks.com/topic/53195-getting-file-mime-type/ Share on other sites More sharing options...
ToonMariner Posted May 27, 2007 Share Posted May 27, 2007 $_FILES['inputname']['type'] wiil give you the mime type of the uploaded file. Link to comment https://forums.phpfreaks.com/topic/53195-getting-file-mime-type/#findComment-262930 Share on other sites More sharing options...
textbox Posted May 28, 2007 Share Posted May 28, 2007 Here is one way i do it. // return the mime type associated with a filename including extension. function getMimeType( $filename ){ $extension = substr( $filename , strrpos( $filename, '.' ) + 1 ); switch( $extension ) { case( 'gif' ) : return 'image/gif'; case( 'jpg' ) : return 'image/jpeg'; case( 'png' ) : return 'image/png'; case( 'txt' ) : return 'text/plain'; case( '3gpp' ) : return 'video/3gpp'; case( 'amr' ) : return 'audio/amr'; default : return '?/?'; } } Link to comment https://forums.phpfreaks.com/topic/53195-getting-file-mime-type/#findComment-262940 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.