Thanks would of had to code my own thing download function but now with this Media view that is all covered, sweet.
On Jul 13, 11:39 am, brian <bally.z...@gmail.com> wrote: > Hi Jörg, > > I'll show you the basics of how I just did this. In my case, the files > are stored above webroot and there's a record for each in the > database. The table was created like so: > > CREATE TABLE item_files > ( > id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, > created DATETIME DEFAULT NULL, > modified DATETIME DEFAULT NULL, > item_id INT(10) NOT NULL, > directory VARCHAR(255) NOT NULL, > basename VARCHAR(64) NOT NULL, > extension VARCHAR(4) NOT NULL, > type VARCHAR(64) NOT NULL, > size INT(11) UNSIGNED NOT NULL, > > FOREIGN KEY (item_id) REFERENCES items (id) ON DELETE CASCADE > ) > ENGINE=MyISAM; > > First, create a directory inside /app. Call it 'files' or something > and put your PDFs in it. These are now inaccessible from the browser. > Don't confuse this with /app/webroot/files, which is accessible. > > In your controller, create a download() method. I'm leaving out a lot > of stuff in my own; this is just the basics. This action uses the > MediaView, which is perfect for serving files that are above webroot. > > public function download($item_file_id) > { > // you'll want to check the login status here ... > > $result = $this->ItemFile->find( > 'first', > array( > 'conditions' => array('ItemFile.id' => $item_file_id), > 'fields' => array('*'), > 'contain' => array( > 'Item' => array( > 'fields' => array('*') > ) > ) > ) > ); > > Configure::write('debug', 0); > $this->view = 'Media'; > > /* MediaView is really irritating > */ > $name = substr( > $result['ItemFile']['basename'], > 0, > -(strlen($result['ItemFile']['extension'])) > ); > > $params = array( > 'id' => $result['ItemFile']['basename'], > 'name' => $name, > 'download' => true, > 'extension' => $result['ItemFile']['extension'], > 'path' => APP.$result['ItemFile']['directory'].DS, > 'mimeType' => array($result['ItemFile']['type']) > ); > $this->set($params); > > } > > That's about it. Have a look in cake/libs/view/media.php to see how > MediaView works. > > On Mon, Jul 13, 2009 at 6:22 AM, joergpb<joer...@gmail.com> wrote: > > > Hello CakePhp Group! > > > My name ist Jörg, form Berlin/Germany. > > > I am quite new to Cake. My problem is that I need a downloadarea where > > the user can only download pdfs ( or any files) from the filesystem > > after he logged in. So the URL to the download has to be dynamic. > > > Any idea how I may get this done with cake? > > > Thanks a lot ! > > > Jörg --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---