本文整理匯總了PHP中app\File::whereId方法的典型用法代碼示例。如果您正苦於以下問題:PHP File::whereId方法的具體用法?PHP File::whereId怎麽用?PHP File::whereId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app\File
的用法示例。
在下文中一共展示了File::whereId方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: DownloadFile
public static function DownloadFile()
{
$id = intval(Input::get('file_id'));
$fileInfo = File::whereId($id)->whereBanned(false)->first();
if ($fileInfo == null) {
abort(404);
}
$config = Config::whereKey('file_dir')->whereApplied(true)->first();
$sourceFile = $config->value . $fileInfo->file_path;
$outFile = $fileInfo->filename;
if (!is_file($sourceFile)) {
abort(404);
}
LogController::LogDownload($id);
$len = filesize($sourceFile);
//獲取文件大小
$filename = basename($sourceFile);
//獲取文件名字
$ctype = FileDownloadController::GetFileExtension($outFile);
//echo $outFile;
header("Cache-Control: public");
header("Content-Type: {$ctype}");
header("Content-Disposition: attachment; filename=" . $outFile);
header("Accept-Ranges: bytes");
$size = filesize($sourceFile);
$range = 0;
if (isset($_SERVER['HTTP_RANGE'])) {
list($a, $range) = explode("=", $_SERVER['HTTP_RANGE']);
str_replace($range, "-", $range);
$size2 = $size - 1;
//文件總字節數
$new_length = $size2 - $range;
header("HTTP/1.1 206 Partial Content");
header("Content-Length: {$new_length}");
header("Content-Range: bytes {$range}{$size2}/{$size}");
} else {
$size2 = $size - 1;
header("Content-Range: bytes 0-{$size2}/{$size}");
header("Content-Length: " . $size);
}
$fp = fopen("{$sourceFile}", "rb");
fseek($fp, $range);
while (!feof($fp)) {
set_time_limit(0);
print fread($fp, 1024 * 8);
flush();
ob_flush();
}
fclose($fp);
exit;
}