Skip to content

Commit

Permalink
Detect encoding of text/plain.
Browse files Browse the repository at this point in the history
  • Loading branch information
qybta committed Feb 27, 2014
1 parent 1227fa3 commit cade4f3
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,17 @@ function cleanmime($v) {
if ($file !== 0) {
$res = pg_query("select filemime, filename, attachment from posts where postid = $file");
list($type, $name, $att) = pg_fetch_row($res);
$att = pg_unescape_bytea($att);
if ($att === null) {
error("Ingen fil her.");
}
if ($type === "text/plain") {
$type = $type."; charset=".mb_detect_encoding($att);
}
header("Content-Type: ".$type);
header("Content-Disposition: inline; filename=\"" . cleanqval($name) . "\"");
header("Cache-Control: public, max-age=1073741824");
echo pg_unescape_bytea($att);
echo $att;
exit;
}

Expand Down

0 comments on commit cade4f3

Please sign in to comment.