This is just an additional answer. A nice tool for this would be link , although having a Unix-based or Linux-based system you can do this via the command line.
Assuming you want to detect other types of mime-type, in Ubuntu there is the command file
, usage example:
file --mime-type arquivo.eml
In PHP (since it was the solution proposed in your answer) you can use 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 usage would look 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 filename=
should contain only the name (not sure if it passed the full name) it would be interesting to pass basename($file)
to get only the same name.
It is also necessary to code, perhaps there is a spacing between the characters of the file name urlencode(basename($filename))
.