improved file download and wiki attachment handling

This commit is contained in:
hyung-hwan 2014-05-18 14:39:13 +00:00
parent f498dba3bf
commit 7462e271c9
2 changed files with 63 additions and 44 deletions

View File

@ -172,21 +172,39 @@ class File extends Controller
else else
{ {
$path = CODEPOT_FILE_DIR . '/' . $file->encname; $path = CODEPOT_FILE_DIR . '/' . $file->encname;
$mtime = @filemtime ($path);
if ($mtime === FALSE) $mtime = time();
header("Last-Modified: " . gmdate("D, d M Y H:i:s", $mtime) . " GMT");
//header("Expires: 0");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename={$name}");
header("Content-Transfer-Encoding: binary");
header('Expires: 0'); $stat = @stat($path);
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); if ($stat === FALSE)
header('Pragma: public'); {
$fsize = @filesize($path); $data['project'] = $project;
if ($fsize !== FALSE) header("Content-Length: {$fsize}"); $data['message'] = "CANNOT GET FILE - {$file->name}";
$this->load->view ($this->VIEW_ERROR, $data);
return;
}
$etag = sprintf ('%x-%x-%x-%x', $stat['dev'], $stat['ino'], $stat['size'], $stat['mtime']);
$lastmod = gmdate ('D, d M Y H:i:s', $stat['mtime']);
header ('Last-Modified: ' . $lastmod . ' GMT');
header ('Etag: ' . $etag);
if ((isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $etag) ||
(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $stat['mtime']))
{
header('Not Modified', true, 304);
flush (); flush ();
return;
}
header('Content-Type: application/octet-stream');
header('Content-Length: ' . $stat['size']);
header('Content-Disposition: attachment; filename=' . $name);
header('Content-Transfer-Encoding: binary');
//header('Expires: 0');
//header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
//header('Pragma: public');
flush ();
$x = @readfile($path); $x = @readfile($path);
if ($x === FALSE) if ($x === FALSE)
{ {

View File

@ -262,31 +262,33 @@ class Wiki extends Controller
{ {
$path = CODEPOT_ATTACHMENT_DIR . "/{$att->encname}"; $path = CODEPOT_ATTACHMENT_DIR . "/{$att->encname}";
$mtime = @filemtime ($path); $stat = @stat($path);
if ($mtime === FALSE) $mtime = time(); if ($stat === FALSE)
{
$data['project'] = $project;
$data['message'] = sprintf (
$this->lang->line('WIKI_MSG_FAILED_TO_READ_ATTACHMENT'), $name);
$this->load->view ($this->VIEW_ERROR, $data);
return;
}
$etag = sprintf ('%x-%x-%x-%x', $stat['dev'], $stat['ino'], $stat['size'], $stat['mtime']);
$lastmod = gmdate ('D, d M Y H:i:s', $stat['mtime']);
header ('Last-Modified: ' . $lastmod . ' GMT');
header ('Etag: ' . $etag);
if ((isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $etag) ||
(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $stat['mtime']))
{
header('Not Modified', true, 304);
flush ();
return;
}
header ('Content-Type: ' . mime_content_type($path)); header ('Content-Type: ' . mime_content_type($path));
header ('Content-Length: ' . $stat['size']);
//header ('Expires: ' . gmdate("D, d M Y H:i:s", time() + 60*60*24*30) . ' GMT'); // 30days header ('Content-Disposition: inline; filename=' . $name);
//header ('Expires: -1');
//header ('Cache-Control: must-revalidate, private');
header ('Cache-Control: max-age=0');
$reqheaders = function_exists('apache_request_headers')? apache_request_headers(): array();
if (isset($reqheaders['If-Modified-Since']) &&
strtotime($reqheaders['If-Modified-Since']) >= $mtime)
{
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $mtime).' GMT', true, 304);
flush ();
}
else
{
header ('Last-Modified: ' . gmdate("D, d M Y H:i:s", $mtime) . ' GMT');
header ("Content-Disposition: filename={$name}");
$len = @filesize($path);
if ($len !== FALSE) header("Content-Length: {$len}");
//header("Content-Transfer-Encoding: binary");
flush (); flush ();
$x = @readfile($path); $x = @readfile($path);
@ -300,7 +302,6 @@ class Wiki extends Controller
} }
} }
} }
}
function _edit_wiki ($projectid, $name, $mode) function _edit_wiki ($projectid, $name, $mode)
{ {