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.
Artisan is the name of the command-line interface included with Laravel. It provides a number of helpful commands for your use while developing your application. It is driven by the powerful Symfony Console component.
To create a new artisan command, we can use the make:command artisan command. This command will make a new command class within the app/Console/Commands catalog. In case the directory does not exist in our laravel project, it'll be automatically made the primary time we run the artisan make:command command.
How about this:
First identify the file which you want to download and then call
string shell_exec ( string $cmd )
you can use wget to get the file.
for example, in your command
$fileName = $this->argument('filename');
$file = url('storage/public/' . $fileName);
shell_exec("wget $file");
$this->info('downloading');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With