如何在php中设置下载路径
how to set the download path in php
我是一名网络开发人员。
DownloadController.php
$local_file = 'file.zip';
$download_file = 'd:\temp\download.zip';
if(file_exists($local_file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($local_file).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($local_file));
readfile($download_file);
}
希望下载'file.zip'和'd:\temp\download.zip'
的下载路径
谁能帮帮我!
谢谢你
您可以使用以下代码下载文件:
return response()->download($pathToFile);
或
return response()->download($pathToFile, $name, $headers)
The download
method may be used to generate a response that forces the user's browser to download
the file at the given path. The download method accepts a file name as the second argument to the method, which will determine the file name that is seen by the user downloading the file. Finally, you may pass an array of HTTP headers as the third argument to the method:
我是一名网络开发人员。
DownloadController.php
$local_file = 'file.zip';
$download_file = 'd:\temp\download.zip';
if(file_exists($local_file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($local_file).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($local_file));
readfile($download_file);
}
希望下载'file.zip'和'd:\temp\download.zip'
的下载路径谁能帮帮我! 谢谢你
您可以使用以下代码下载文件:
return response()->download($pathToFile);
或
return response()->download($pathToFile, $name, $headers)
The
download
method may be used to generate a response that forces the user's browser todownload
the file at the given path. The download method accepts a file name as the second argument to the method, which will determine the file name that is seen by the user downloading the file. Finally, you may pass an array of HTTP headers as the third argument to the method: