我在代码点火器控制器中创建了一个函数,以在单击下载后返回文件。它适用于所有设备,但不适用于仅iPhone。我不明白是什么问题,或者我缺少什么。
仅在iPhone设备上,它会返回垃圾。
控制器方法:
public function download_document($project_id,$file_name){
$doc_path=site_url('documents/projects/'.$project_id.'/'.$file_name);
header('Content-Description: File Transfer');
header('Content-Type: application/pdf');
header('Content-Disposition: attachment;
filename='.basename($doc_path));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($doc_path));
ob_clean();
flush();
$file= readfile($doc_path);
// The PDF source is in original.pdf
return $file;
}
调用方法的输出