Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Force Download
  • How does one force the download of a file?
    For example, I have an app that dynamically creates a zip file and then makes it available for download.
    In plain PHP I would do something like this:
    <?php
    $file = 'monkey.gif';
    
    if (file_exists($file)) {
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename='.basename($file));
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
        header('Content-Length: ' . filesize($file));
        ob_clean();
        flush();
        readfile&#40;$file&#41;;
        exit;
    }
    ?>
    
    What is the equivalent in Fuel?
  • File::download(), if you're on develop branch (it was added after RC3). It will autodetect the correct mime type, but you can override that, as well as the filename.
  • Thanks WanWizard,
    Works like a charm.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion