diff options
Diffstat (limited to 'lib/files.php')
-rw-r--r-- | lib/files.php | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/lib/files.php b/lib/files.php index abb1617c25e..c705d2adb1a 100644 --- a/lib/files.php +++ b/lib/files.php @@ -46,6 +46,7 @@ class OC_Files { public static function get($dir, $files, $only_header = false) { $xsendfile = false; if (isset($_SERVER['MOD_X_SENDFILE_ENABLED']) || + isset($_SERVER['MOD_X_SENDFILE2_ENABLED']) || isset($_SERVER['MOD_X_ACCEL_REDIRECT_ENABLED'])) { $xsendfile = true; } @@ -61,7 +62,8 @@ class OC_Files { $zip = new ZipArchive(); $filename = OC_Helper::tmpFile('.zip'); if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE)!==true) { - exit("cannot open <$filename>\n"); + $l = OC_L10N::get('lib'); + throw new Exception($l->t('cannot open "%s"', array($filename))); } foreach ($files as $file) { $file = $dir . '/' . $file; @@ -92,7 +94,8 @@ class OC_Files { $zip = new ZipArchive(); $filename = OC_Helper::tmpFile('.zip'); if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE)!==true) { - exit("cannot open <$filename>\n"); + $l = OC_L10N::get('lib'); + throw new Exception($l->t('cannot open "%s"', array($filename))); } $file = $dir . '/' . $files; self::zipAddDir($file, $zip); @@ -170,7 +173,22 @@ class OC_Files { private static function addSendfileHeader($filename) { if (isset($_SERVER['MOD_X_SENDFILE_ENABLED'])) { header("X-Sendfile: " . $filename); + } + if (isset($_SERVER['MOD_X_SENDFILE2_ENABLED'])) { + if (isset($_SERVER['HTTP_RANGE']) && + preg_match("/^bytes=([0-9]+)-([0-9]*)$/", $_SERVER['HTTP_RANGE'], $range)) { + $filelength = filesize($filename); + if ($range[2] == "") { + $range[2] = $filelength - 1; + } + header("Content-Range: bytes $range[1]-$range[2]/" . $filelength); + header("HTTP/1.1 206 Partial content"); + header("X-Sendfile2: " . str_replace(",", "%2c", rawurlencode($filename)) . " $range[1]-$range[2]"); + } else { + header("X-Sendfile: " . $filename); + } } + if (isset($_SERVER['MOD_X_ACCEL_REDIRECT_ENABLED'])) { header("X-Accel-Redirect: " . $filename); } @@ -204,16 +222,11 @@ class OC_Files { if (!OC_Config::getValue('allowZipDownload', true)) { $l = OC_L10N::get('lib'); header("HTTP/1.0 409 Conflict"); - $tmpl = new OC_Template('', 'error', 'user'); - $errors = array( - array( - 'error' => $l->t('ZIP download is turned off.'), - 'hint' => $l->t('Files need to be downloaded one by one.') - . '<br/><a href="javascript:history.back()">' . $l->t('Back to Files') . '</a>', - ) + OC_Template::printErrorPage( + $l->t('ZIP download is turned off.'), + $l->t('Files need to be downloaded one by one.') + . '<br/><a href="javascript:history.back()">' . $l->t('Back to Files') . '</a>' ); - $tmpl->assign('errors', $errors); - $tmpl->printPage(); exit; } @@ -236,17 +249,12 @@ class OC_Files { if ($totalsize > $zipLimit) { $l = OC_L10N::get('lib'); header("HTTP/1.0 409 Conflict"); - $tmpl = new OC_Template('', 'error', 'user'); - $errors = array( - array( - 'error' => $l->t('Selected files too large to generate zip file.'), - 'hint' => 'Download the files in smaller chunks, seperately' - .' or kindly ask your administrator.<br/><a href="javascript:history.back()">' - . $l->t('Back to Files') . '</a>', - ) + OC_Template::printErrorPage( + $l->t('Selected files too large to generate zip file.'), + $l->t('Download the files in smaller chunks, seperately or kindly ask your administrator.') + .'<br/><a href="javascript:history.back()">' + . $l->t('Back to Files') . '</a>' ); - $tmpl->assign('errors', $errors); - $tmpl->printPage(); exit; } } |