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 Quote Link to comment 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) Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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); ?> Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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)); Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.