1

This is my helper

function fileDownload(EloquentFile $file, bool $stream): bool {

    $file_dir = $file->dir . '/';
    $file_url = $file_dir . $file->id;

    $stream = $stream === true ? 'attachment' : 'inline';

    if (Storage::disk('s3')->has($file_url)) {
        header('Content-type: ' . $file->mime);
        header('Content-Disposition: ' . $stream . '; filename=' . $file->name);
        header('Content-Length: ' . $file->size);
        echo Storage::disk('s3')->get($file_url);

        //die(); do I have to put die here?
    }

    abort(404);
}

Question - does commented die() is required here or can I skip it?

Matt Komarnicki
  • 5,198
  • 7
  • 40
  • 92
  • well, if output buffering is enabled, and you DON'T exit, then you proceed on to the `abort(404)`, whi then causes your download page to say "not found", AND send out the download data. confusing, to say the lease. "couldn't find what you wanted, but here's what you wanted anyways" – Marc B Feb 11 '16 at 21:59
  • 1
    Use a return statement instead. – Neo Feb 11 '16 at 22:29
  • Possible duplicate of [PHP: Utilizing exit(); or die(); after header("Location: ");](http://stackoverflow.com/questions/8665985/php-utilizing-exit-or-die-after-headerlocation) – Peyman Mohamadpour Feb 11 '16 at 23:41
  • https://laravel.com/docs/5.1/responses#file-downloads – The Alpha Feb 11 '16 at 23:44

1 Answers1

0

I would suggest against using any die or exit statements and just directly return the response.

For your example it would be

return Storage::disk('s3')->get($file_url);
Marcel
  • 1