This is just an additional to the answer. A cool tool for this would be the http://filext.com, although having a Unix-based or Linux-based system is possible to do this via the command line.
Assuming you want to detect other types of mime-type, in Ubuntu there is the command file
, example of use:
file --mime-type arquivo.eml
In PHP (since it was the solution proposed in your reply) you can use the fileinfo
, something like:
function mimeType($file)
{
$mimetype = false;
if (class_exists('finfo')) {//PHP5.4+
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mimetype = finfo_file($finfo, $file);
finfo_close($finfo);
} else if (function_exists('mime_content_type')) {//php5.3 ou inferiror
$mimetype = mime_content_type($file);
}
return $mimetype;
}
The use would be something like:
$mime = mimeType($file);
if (!$mime) {
die('Formato desconhecido');
} else {
$filename = urlencode(basename($file));
header("Content-Disposition: attachment; filename=$filename");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: $mime");
}
Note that I coded the filename=
should contain only the name (not sure if you passed the full name) it would be interesting to go through basename($file)
to obtain only the same name.
It is also necessary to encode, if you have spacing between the characters of the file name urlencode(basename($filename))
.