Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
How to send a file as download
  • Hey, Im not sure, if this is the right way to send a hidden file to an authenticated user with Fuel. A normal download should not be allowed. How do you solve this?
    class Controller_Download extends Controller_Template
    {
     public function action_index($file_id)
     {
      $this->auto_render = false;
      
      $file = Model_File::find($file_id);
     
      $this->response->set_header('Content-Type', 'application/pdf');
      $this->response->set_header('Content-Disposition', 'attachment; filename="'.$file->name.'"');
      
      readfile($file->path); // I'm not sure here 
      
      return $this->response; // And here ???
         }
    }
    
  • Thank you. I knew there is an easy way. Felix

Howdy, Stranger!

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

In this Discussion