0
votes

So basically I am trying to download a file.

I Have the action:

public function getfile() {
        $this->autoRender = false;
        $accesskey = 'mrPQVeJF8VFXpSq';
        $data = $this->File->find('first', array('conditions' => array('File.accesskey =' => $accesskey)));   

        $filepath = substr($data['File']['path'], 17);

        $this->response->file($filepath, array('download' => true, 'name' => $data['File']['name']));

         return $this->response;
    }

this throws an error : (i guess the line with $this->response->file())

Fatal Error Error: Class 'File' not found File: C:\wamp\www\project\lib\Cake\Network\CakeResponse.php Line: 1347

1

1 Answers

1
votes

The class File is an Utility of cake. So, using it as a model will probably give you trouble. I recommend you change it. Read more about reserve cake and php words here. That may be the cause of your error.

And the other cause of that error is that you are not in FilesController, and are trying to call the Find model there. for that read how to load models from other controllers (look for ClassRegistry::init or $this->loadModel().

I'm just guessing here, because your are "guessing the line giving trouble is $this->response->file()". You may get a more accurate response if you do not guess and debug exactly what line is giving you that error.