Closed 262925 closed 4 years ago
Could you please elaborate on that?
@odan Odan, A router link a page called /my-musics(twig tpl). In that page I had list of tracks which is loads from database. Below that a click to download all tracks as zip which is I stored in my slim app dir dts/storage/04/mymusic.zip - I wanted know give the link to download without showing my storage directory.
You could read (or generate) a file from anywhere (internal filesystem, database etc) and then put content into the $response body. Here is an older article for Slim 3, but the same principle applies to Slim 4.
https://odan.github.io/2017/12/16/creating-and-downloading-excel-files-with-slim.html
I didn't yet tried above but i found following and working too. Download Zip Files Dynamically in PHP - Do you think which is good way on slim 4?
Code
Generally for Slim this is not a good way, because in Slim you should use the response object. For very large files you could also use streams (as written in my article).
I did followed. But i am getting error:
500 Internal Server Error - Error details: [0] Class 'Slim\Http\Stream' not found in C:\wamp\www\dts\src\Controllers\DownloadController.php on line 46.
Code:
Of course it must be a litte bit adapted to Slim 4, because the Stream class has been removed resp. abstracted away to other PSR-7 implementations like slim/psr7 etc. $stream = new \Slim\Psr7\Stream(...);
Cool.. works!
Is this possible to add a link to download with storage directory with slim 4 and how?