dimanche 2 octobre 2016

File keeps being downloadable

In Laravel I have the following code to download a .flac file:

public function play($id){
    //disable execution time limit when downloading a big file.
    set_time_limit(0);

    /** @var \League\Flysystem\Filesystem $fs */
    $fs = Storage::disk('local')->getDriver();

    $fileName = 'flac/'.Flac::findOrFail($id)->file;

    $metaData = $fs->getMetadata($fileName);
    $stream = $fs->readStream($fileName);
    if (ob_get_level()) ob_end_clean();
    return response()->stream(
        function () use ($stream) {
            fpassthru($stream);
        },
        200,
        [
            'Content-Type' => $metaData['type'],
            'Content-disposition' => 'attachment; filename="' . $metaData['path'] . '"',
        ]);
}

The method is accessed by a route. However, when I place a dd('test') in the method like here:

public function play($id){
    //disable execution time limit when downloading a big file.
    dd('test');
    set_time_limit(0);
    ...

And I access the url, the file keeps downloadable. Also whenever I change the file name or what not, it keeps downloading that file. Why?

Bottom line is that I want to download a large flac file when the play method gets executed by a GET request. Thanks in advance!

F.Y.I., I'm using the flac files with Aurora javascript flac decoder.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire