我正在使用laravel Artisan Commands从公共文件夹下载文件.
其实我想下载一个我在公共文件夹中成功制作的zip文件.
当我按下按钮点击方法时,我能够下载文件.
但是当我在控制台中执行命令时,它不起作用,也不会抛出任何错误.
public function downloadExportRawData() {
$a=public_path().'/temp/rawexport/rawexportproduct.zip';
$path='/temp/rawexport/rawexportproduct.zip';
if(file_exists('temp/rawexport/rawexportproduct.zip')){
return Response::download($a);
}else{
return "hello";
}
}
试过这个……
public static function downloadZip($rand_folder,$zipname,$fileName) {
header('Content-Type: application/force-download');
header('Content-Disposition: attachment; filename="' . $fileName . '.zip"');
header('Content-Length: ' . filesize($zipname));
$handle = fopen($zipname,'rb');
//exec("rm -r ".$temp);
while (!feof($handle)) {
echo fread($handle,1048576);
ob_flush();
flush();
}
fclose($handle);
// exec("rm -r " . $rand_folder);
}
而命令是
PHP artisan product:export --from=http://localhost/valuable-app/dev-master/rest_app/public/ --productid=5b273b0e4bb5995b108b4576 --tokenexport=354c3ddb2bd45aa6e5c4f749749b0b58cbacef48
主要问题是它正在通过控制器中的功能但不下载它.
我试图回应它以zip格式打印代码的响应意味着一个编码的表单,其中有一些与我的zip文件相关的意思是它打印zip而不是下载它.
我第一次使用Artisan.知道如何使用用户定义的Artisan命令下载该文件.
我在过去两周尝试这个但是没能做任何事情.