How do I access a file created in the storage_path () folder in laravel?

3

I create a pdf with the package barryvdh / laravel-dompdf as follows:

public function generarPdf(Request $req) {
    $datos = $req->data;
    Debugbar::info($datos);
    $archivo = storage_path().'\pdf\equipos\'.$datos[1].'-'.$datos[2].'.pdf';

    $pdf = \PDF::loadView('equipos.pdf_vista', $datos);
    $pdf->setPaper('a4');
    $pdf->setWarnings(false);
    $pdf->save($archivo);
    return $pdf->loadFile($archivo);
}

This is created correctly, my problem is when I try to access the file to show it to the user, it appears to me that the access is denied, example:

  

Permission denied on C: \ virtualhost \ System \ storage \ pdf \ computers \ 00001-Ulma1.pdf.

    
asked by Pablo Contreras 23.06.2017 в 09:23
source

2 answers

1

Taking into account that this folder is not part of the "public" zone of Laravel, the documentation suggests making a symbolic link from public/storage to storage/app/public .

There is even a command to generate this link:

php artisan storage:link

You can see the related documentation: link

    
answered by 23.06.2017 в 15:15
0

A solution to your problem is that the solutions with HTTP Responses from laravel.

Something I do personally, is that I avoid handling symbolic links .

What I do is that I look for the file with storage_path () or public_path () ending with the path where it should be for example.

$rutaDeArchivo = storage_path() + "ruta_del_archivo_dentro_de_laravel_storage"

and I end with

return response()->download($rutaDeArchivo);

With this you must download your file.

If I find the code snippet where I do this, I update this answer.

    
answered by 01.07.2017 в 05:00