I am using laravel Artisan Commands to download a file from public folder .
Actually i want to download a zip file which i have successfully made in public folder.
I am able to download the file when I call the methods on button click.
But when I execute the command in console it does not work and also not throw any error.
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";
}
}
Tried this also...
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);
}
and the command is
php artisan product:export --from=http://localhost/valuable-app/dev-master/rest_app/public/ --productid=5b273b0e4bb5995b108b4576 --tokenexport=354c3ddb2bd45aa6e5c4f749749b0b58cbacef48
The main problem is that it is going through the function in controller but not downloading it. And I tried to echo the response it prints code in zip form means a encoded form which have something related to my zip file means its printing the zip not downloading it. I am using Artisan first time. Any idea how to download that file using using user-defined Artisan command.
I am trying this from last two weeks but not able to do anything.