Laravel-excel: The filename and the fallback cannot contain the "/" and "\" characters

Created on 8 Jul 2020  路  6Comments  路  Source: Maatwebsite/Laravel-Excel

Versions

  • PHP version: 7.3.5
  • Laravel version: 7.x
  • Package version: 3.1.19

Description

I get an error while exporting. The way of use is as follows. Can you help me ?

Error: InvalidArgumentException: The filename and the fallback cannot contain the "/" and "\" characters.

Code:

$excel_database_product = DB::table('product_excel')->get()->toArray();

$result= new ExcelArrayExport($excel_database_product );

Excel::download($result, storage_path("new_product.xlsx"));

class ExcelArrayExport implements FromArray
{
protected $array;

public function __construct(array $array)
{
    $this->array = $array;
}

public function array(): array
{
    return  json_decode( json_encode($this->array), true);
}

}

question

Most helpful comment

Excel::download($result, storage_path("new_product.xlsx")); should be Excel::download($result, 'new_product.xlsx'); Download expects a filename not a filepath.

All 6 comments

Excel::download($result, storage_path("new_product.xlsx")); should be Excel::download($result, 'new_product.xlsx'); Download expects a filename not a filepath.

So how can I specify the file path?

Why do you want to specify the file path for a download?

I want to replace the excel file in a folder

You need ::store not ::download then

Thanks for your help :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alejandri picture alejandri  路  3Comments

pamekar picture pamekar  路  3Comments

vandolphreyes picture vandolphreyes  路  3Comments

lucatamtam picture lucatamtam  路  3Comments

kurianic picture kurianic  路  3Comments