Canman2005 Posted April 20, 2007 Share Posted April 20, 2007 Hi all I have the following; $file = $_GET['filename']; How can I print on screen, the mine type for this file? Is this easy? Thanks Ed Link to comment https://forums.phpfreaks.com/topic/47826-print-mime-type/ Share on other sites More sharing options...
Glyde Posted April 20, 2007 Share Posted April 20, 2007 Well first of all, using $_GET means you're accessing a querystring variable, so is your page being loaded such as myscript.php?filename=/path/to/somefile.onyourcomputer? If so, use mime_content_type($file) Link to comment https://forums.phpfreaks.com/topic/47826-print-mime-type/#findComment-233677 Share on other sites More sharing options...
Moon-Man.net Posted April 20, 2007 Share Posted April 20, 2007 If you uploaded this file from a html form, this page will help http://au3.php.net/features.file-upload -- Nathan Link to comment https://forums.phpfreaks.com/topic/47826-print-mime-type/#findComment-233679 Share on other sites More sharing options...
Canman2005 Posted April 20, 2007 Author Share Posted April 20, 2007 Hi If I try that, I get the error Fatal error: Call to undefined function mime_content_type() in C:\www\nagc\members\elements\download.php on line 3 Is there anymore options or what do I need to adjust or add? Thankd Link to comment https://forums.phpfreaks.com/topic/47826-print-mime-type/#findComment-233681 Share on other sites More sharing options...
Canman2005 Posted April 20, 2007 Author Share Posted April 20, 2007 Nope, there files already stored on my server, this is for internal use so there is no security issue Link to comment https://forums.phpfreaks.com/topic/47826-print-mime-type/#findComment-233682 Share on other sites More sharing options...
Glyde Posted April 20, 2007 Share Posted April 20, 2007 <?php $finfo = finfo_open(FILEINFO_MIME); // return mime type ala mimetype extension echo finfo_file($finfo, $file); finfo_close($finfo); ?> Link to comment https://forums.phpfreaks.com/topic/47826-print-mime-type/#findComment-233686 Share on other sites More sharing options...
Canman2005 Posted April 20, 2007 Author Share Posted April 20, 2007 With that one, I get Fatal error: Call to undefined function finfo_open() in Any ideas? Thanks so far everyone Link to comment https://forums.phpfreaks.com/topic/47826-print-mime-type/#findComment-233693 Share on other sites More sharing options...
Guest prozente Posted April 20, 2007 Share Posted April 20, 2007 You have to install the extension first ( http://pecl.php.net/package/Fileinfo ) You also have the option to use the older mime_content_type Link to comment https://forums.phpfreaks.com/topic/47826-print-mime-type/#findComment-233701 Share on other sites More sharing options...
Canman2005 Posted April 20, 2007 Author Share Posted April 20, 2007 Hi mime_content_type doesnt work on my server & im not able to install anything on it. Is there no way around it, even with a complex function script? I've hunted online but not found a script which works yet Any advice anyone? Thanks Link to comment https://forums.phpfreaks.com/topic/47826-print-mime-type/#findComment-233703 Share on other sites More sharing options...
Guest prozente Posted April 20, 2007 Share Posted April 20, 2007 If this is linux and exec is enabled then you can do something like echo exec('file -i '.escapeshellcmd($filename)); Link to comment https://forums.phpfreaks.com/topic/47826-print-mime-type/#findComment-233712 Share on other sites More sharing options...
Canman2005 Posted April 20, 2007 Author Share Posted April 20, 2007 Hi prozente The server wont allow such a function, sadly I cant change any of the servers config and its all passworded up Should I give up? Link to comment https://forums.phpfreaks.com/topic/47826-print-mime-type/#findComment-233715 Share on other sites More sharing options...
Guest prozente Posted April 20, 2007 Share Posted April 20, 2007 You could associate a MIME type with the file extensions. There are pre-made classes that do this but the down side is it doesn't look at the content of the file to verify this. You could create a script to look at the file header to determine the MIME but you'd have to research each file format and with the number of file types this could take some time. Link to comment https://forums.phpfreaks.com/topic/47826-print-mime-type/#findComment-233723 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.