public function onDownloadReport()
{
try{
// $fileName = isset($_REQUEST['file_name']) ? str_replace(" ", "_", trim($_REQUEST['file_name'])) : '';
// $baseId = isset($_REQUEST['base_id']) ? str_replace(" ", "_", trim($_REQUEST['base_id'])) : '';
$fileName = isset($_REQUEST['file_name']) ? trim($_REQUEST['file_name']) : '';
$baseId = isset($_REQUEST['base_id']) ? trim($_REQUEST['base_id']) : '';
if(!$fileName || !$baseId)
{
throw new Exception('缺少参数');
}
$path = AppRoot . '/Temp/apt_report/' . $baseId . '/';
$res = file_exists($path . $fileName);
if($res)
{
$fileSize = filesize($path . $fileName);
Header ( "Content-type: application/octet-stream" );
Header ( "Accept-Ranges: bytes" );
Header ( "Accept-Length: " . $fileSize );
Header ( "Content-Disposition: attachment; filename=" . $fileName );
readfile($path . $fileName);
}
else
{
$this->ajaxReturn(array(
'code' => -1,
'msg' => "文件夹不存在"
));
}
}
catch(Exception $e)
{
$this->ajaxReturn(array(
'code' => -1,
'msg' => $e->getMessage()
));
}
}
php读pdf格式文件
最新推荐文章于 2023-12-20 09:51:07 发布