Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vandan's avatar
Level 13

how to store excel download file path

i want download excel sheet path store in varibale how to do it any suggestion ?

$file = Excel::download(new UsersExport, 'Sales Register 2019 Cr.xlsx');    
    
$data = array('name'=>"byte and bits");
     
        \Mail::send('front.mail', $data, function($message) use($path){
            
        $message->to('[email protected]')
            
        ->subject('Sales Register 2019 Excelsheet');
            
        $message->from('[email protected]','byte and bits');
            
        $message->attachData($path,'Sales Register 2019 Cr.xlsx');                                      
        
    });
0 likes
47 replies
vandan's avatar
Level 13

@SNAPEY - i can try already but

error The Response content must be a string or object implementing __toString(), "boolean" given.

cant understand please guide me

vandan's avatar
Level 13

@BOBBYBOUWMANN - i try already but error fire

$file = Excel::store(new UsersExport, 'Sales Register 2019 Cr.xlsx');    

    $data = array('name'=>"byte and bits"); 

    \Mail::send('front.mail', $data, function($message) use($file){
            
            $message->attachData($file,'Sales Register 2019 Cr.xlsx');                                      
        
});

The Response content must be a string or object implementing __toString(), "boolean" given.

Snapey's avatar

I can't see in the docs that the store method returns anything ? Your error would imply that a boolean is returned suggesting a true/false state for the store.

You need to construct the filepath yourself.

try

$filename = 'Sales Register 2019 Cr.xlsx';

Excel::store(new UsersExport, $filename); 

$file = storage_path($filename);
vandan's avatar
Level 13

steel my screen print like D:\laragon\www\hello\storage\Sales Register 2019 Cr.xlsx

and my mail succesfully send but file not open correcupted like popup

Snapey's avatar

I don't know what that lot means.

vandan's avatar
Level 13

@SNAPEY - run the code file can;t export and mail send but excel file cannot open in mail

$file = 'C:\Users\Vandan\Downloads';
    
Excel::download(new UsersExport,$file);
    
$file = storage_path($file);
    
    $data = array('name'=>"byte and bits"); 
    
    \Mail::send('front.mail', $data, function($message) use($file){
            
        $message->to('[email protected]')
            
        ->subject('Sales Register 2019 Excelsheet');
            
        $message->from('[email protected]','byte and bits');
            
        $message->attachData($file,'Sales Register 2019 Cr.xlsx');                                      
        
    });

    User::truncate();
    

return $file;

Snapey's avatar

Why did you not just copy my example?

Where is the filename here

$file = 'C:\Users\Vandan\Downloads';

Excel::download(new UsersExport,$file);

$file = storage_path($file);

And you are still using download

vandan's avatar
Level 13

@SNAPEY - sorry use store and steel error

No ReaderType or WriterType could be detected. Make sure you either pass a valid extension to the filename or pass an explicit type.

$file = 'import_file';
    
Excel::store(new UsersExport,$file);
    
$file = storage_path($file);

actually i try to export excel file with mail send excelsheet so this code is valid or not any suggestion please

Snapey's avatar

Make sure you either pass a valid extension to the filename

WTF 'import_file'

vandan's avatar
Level 13

@SNAPEY - sorry

how to get file extension ?

can't understand please help me

vandan's avatar
Level 13

@BOBBYBOUWMANN - please help me i try to export file with mail send excelsheet so my code is valid or not?

Snapey's avatar
$filename = 'Sales Register 2019 Cr.xlsx';

Excel::store(new UsersExport, $filename); 

$file = storage_path($filename);

see above? See .xlsx? Thats the file extension.

vandan's avatar
Level 13

@SNAPEY - Try ALready Not Working

$filename = 'Sales Register 2019 Cr.xlsx';
    
Excel::store(new UsersExport, $filename); 
    
$path = storage_path($filename);

output only file path display in excel file not record fetch look like : "D:\laragon\www\hello\storage\Sales Register 2019 Cr.xlsx"

jlrdw's avatar

Well like Jeffrey reminded me one time we were all new to this stuff at one time.

Why don't you go to that site and actually work some of those examples and just take your time and learn how to do it correctly.

vandan's avatar
Level 13

@JLRDW - ok i learn it but please help me out this error first

jlrdw's avatar

I would say work those examples first that way you will learn. Bedtime here in Texas.

Snapey's avatar

When you run this code, does it create the file in the storage folder?

$filename = 'Sales Register 2019 Cr.xlsx';

Excel::store(new UsersExport, $filename); 

$file = storage_path($filename);

You then need your original code to send an email with $file as an attachment

Have you tried that?

vandan's avatar
Level 13

@SNAPEY - yes i try this see

$filename = 'Sales Register 2019 Cr.xlsx';
    
Excel::store(new UsersExport, $filename); 
    
$path = storage_path($filename);
    
    $data = array('name'=>"byte and bits"); 
        
    \Mail::send('front.mail', $data, function($message) use($path){
    
    $message->to('[email protected]')
    
            ->subject('Sales Register 2019 Excelsheet');
    
    $message->from('[email protected]','byte and bits');
    
    $message->attachData($path,'Sales Register 2019 Cr.xlsx'); 
    
});
Snapey's avatar

"Yes I try this see"

What does that tell me? How am I supposed to help?

vandan's avatar
Level 13

@SNAPEY - when file send to mail but file can't open may be file not send correct path so how to correct solution for this code

when i try to downlaod file error like file is correcpted or not valid extension

vandan's avatar
Level 13

@SNAPEY - i try hard

$filename = '.xlsx';
        
Excel::store(new UsersExport, $filename);
        
$path = storage_path($filename);

after file successfully download but data cant fetch

look like only path can store in downlaod file

Snapey's avatar

Unfortunately I cannot teach you how to use a computer through this forum.

vandan's avatar
Level 13

@SNAPEY - sort and sweet

maatwebsite packages use in my project i try to export excel file and mail send while file export

how to mail send with excel file here is my code

i cant sleep to 2 days beacuse my code was not excute so please help me out

ftiersch's avatar

attachData() attaches raw data, not a file from disk.

Use attach() instead.

vandan's avatar
Level 13

@FTIERSCH - i try this attach()

error fire Unable to open file for reading [D:\laragon\www\hello\storage.xlsx]

Next

Please or to participate in this conversation.