Re: Mime Types
| From: | christian haines | Date: | Fri, 04 Oct 2002 07:11:27 +0000 |
| Subject: | Re: Mime Types | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-118818@lists.php.net to get a copy of this message | ||
you could use the command "file -bin your_filename" and capture the output using popen or
exec.
i have found this to work well..
seee below....
function mimetype($file)
{
// execute command
$fp = popen("file -bin $file","r");
// determine mimetype to output
if(!$fp)
{
// default mimetype if no mimetype exists
$mimetype="application/octet-stream";
}
else
{
// iterate through return value to determine mimetype
while($string=fgets($fp, 1024))
{
$mimetype .= $string;
}
pclose($fp);
}
// return output
return $mimetype;
}
Php List wrote:
> Hi,
> Is it possible to get a mime type of a file?
> I need to be able to attach files, but I won't always know the mime type of what is being
> attached.
> I could look at the extension of the file for a general Idea, but I wouldn't know if a
> .jpg file is an image/jpg or image/jpeg.(progressive) and there seems to be a difference between the
> two.
>
> Thanks for any help.
> Chris