Skip to content

Commit

Permalink
Merge pull request #44 from deseven/patch-1
Browse files Browse the repository at this point in the history
Открытие файлов без предварительного сохранения #2
  • Loading branch information
pihel committed Sep 13, 2015
2 parents 401f822 + 5a2ea32 commit d7a595c
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions get.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
<?
require_once('lib/init.php');

if(!function_exists('mime_content_type')) {
if (extension_loaded('fileinfo')) {
function mime_content_type($filename) {
$finfo = new finfo(FILEINFO_MIME_TYPE);
$ctype = $finfo->file($filename);
return $ctype;
}
} else {
function mime_content_type($filename) {
return "application/octet-stream";
}
}
}

$file = "";
$id = intval($_GET['id']);
if(empty($id)) exit;
Expand All @@ -14,14 +28,19 @@
if (ob_get_level()) {
ob_end_clean();
}
$defctype = "application/octet-stream";
$ctype = mime_content_type($file);
if (!$ctype) {
$ctype = $defctype;
}
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . $name);
header('Content-Type: ' . $ctype);
header('Content-Disposition: inline; filename=' . $name);
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file);
exit;
}
}

0 comments on commit d7a595c

Please sign in to comment.