1
我有如下的代碼來下載一個PDF在laravel爲什麼當我嘗試在laravel下載PDF文件時,打開一個具有奇怪字符的文件?
控制器
public function doDownload($id){
$servicio = Servicio::find($id);
$array = explode('/', $servicio->RutaPDF);
$path = '/home/web-apps/marsur/public/servicio/'.$array[1].'/ordedeservicio.pdf'; //array[1] contain a number
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=" . urlencode($path));
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Description: File Transfer");
header("Content-Length: " . filesize($path));
flush(); // this doesn't really matter.
$fp = fopen($path, "r");
while (!feof($fp))
{
echo fread($fp, 65536);
flush(); // this is essential for large downloads
}
fclose($fp);
}
路線
Route::get('servicio/download/{id}', array('uses' => '[email protected]'));
,當我用Postman
測試,這似乎
我該如何解決?