jordanwb Posted December 1, 2007 Share Posted December 1, 2007 I'm making my own proxy using PHP and want to do is able to output a jpeg file (example) or another format using the header command. What I'd like to know is how to get the mime type of a file. Quote Link to comment https://forums.phpfreaks.com/topic/79723-how-to-get-the-mime-type-of-a-file/ Share on other sites More sharing options...
toplay Posted December 1, 2007 Share Posted December 1, 2007 New way: http://us2.php.net/manual/en/function.finfo-file.php http://us2.php.net/manual/en/ref.fileinfo.php Old way: http://us2.php.net/manual/en/function.mime-content-type.php Quote Link to comment https://forums.phpfreaks.com/topic/79723-how-to-get-the-mime-type-of-a-file/#findComment-403727 Share on other sites More sharing options...
jordanwb Posted December 1, 2007 Author Share Posted December 1, 2007 I tried the first one using a function that was created by someone there and I get this error: Fatal error: Call to undefined function finfo_open() in D:\xampp\htdocs\jproxy\includes\file_parser.php on line 31 For mime_content_type I don't get any results: function output () { $num_lines = count ($this->html); $mime_type = mime_content_type ($this->file); print $mime_type; //header("Content-type:".$mime_type); //print_r ($this->html); } $this->file is created in the constructor and the path is correct. Perhaps mime_content_type doesn't work with files that are on another server? Quote Link to comment https://forums.phpfreaks.com/topic/79723-how-to-get-the-mime-type-of-a-file/#findComment-403746 Share on other sites More sharing options...
MadTechie Posted December 1, 2007 Share Posted December 1, 2007 <?php function output () { $num_lines = count ($this->html); $finfo = finfo_open(FILEINFO_MIME); $mime_type = finfo_file($finfo, $this->file); finfo_close($finfo); print $mime_type; //header("Content-type:".$mime_type); //print_r ($this->html); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/79723-how-to-get-the-mime-type-of-a-file/#findComment-403752 Share on other sites More sharing options...
toplay Posted December 1, 2007 Share Posted December 1, 2007 You have to have it installed and that's why I gave you this link with installation instructions: http://us2.php.net/manual/en/ref.fileinfo.php The other function as per docs state that magic.mime file is needed/used. The code example in the manual shows specifying a path and not a URL, so I don't think you can get the mime type from another server if that's what you're trying to do. Quote Link to comment https://forums.phpfreaks.com/topic/79723-how-to-get-the-mime-type-of-a-file/#findComment-403754 Share on other sites More sharing options...
MadTechie Posted December 1, 2007 Share Posted December 1, 2007 Ahh remote file.. i guess one option would be using sockets.. Quote Link to comment https://forums.phpfreaks.com/topic/79723-how-to-get-the-mime-type-of-a-file/#findComment-403760 Share on other sites More sharing options...
jordanwb Posted December 1, 2007 Author Share Posted December 1, 2007 What about determining the mime type based on the extension? I've heard that it may not always be reliable. Quote Link to comment https://forums.phpfreaks.com/topic/79723-how-to-get-the-mime-type-of-a-file/#findComment-403766 Share on other sites More sharing options...
jordanwb Posted December 11, 2007 Author Share Posted December 11, 2007 Hello? Quote Link to comment https://forums.phpfreaks.com/topic/79723-how-to-get-the-mime-type-of-a-file/#findComment-411482 Share on other sites More sharing options...
roopurt18 Posted December 11, 2007 Share Posted December 11, 2007 What about determining the mime type based on the extension? I've heard that it may not always be reliable. That is correct, it is not reliable. Quote Link to comment https://forums.phpfreaks.com/topic/79723-how-to-get-the-mime-type-of-a-file/#findComment-411488 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.