Actually, using a media view would be the better bet. Already deals with everything for you.
On Aug 26, 3:30 pm, Jon Bennett <jmbenn...@gmail.com> wrote: > Hi, > > > I am uploading files(images, mp3s etc) to my webroot /files/ folder. > > The files are named "<their id number>.<their extension>". Without any > > custom routing I can access these files by "/files/343.png". > > > I would like to access this file by using the URL "/files/343- > > sometitle.png" as well. At the moment I can do this by using a custom > > route and an action, but this just redirects and so the URL displays "/ > > files/343.png" - I would like the URL to not change and for the file > > to be displayed as it would be normally. > > You're nearly there. What you need to do is use echo > file_get_contents() in a controller method, eg: > > public function img($filename='') > { > $this->autoRender = false; > > // check file exists > if (!file_exists(WWW_ROOT.'files'.DS.$filename)) > return; > > // output file - very crude as it is, you'd want to set the correct > header/mime type etc > echo file_get_contents(WWW_ROOT.DS.'files'.DS.$filename); > > } > > this only checks for a file with a real name, you'll want to strip out > anything other than the ID.ext > > hth > > Jon > > -- > > jon bennett > w:http://www.jben.net/ > iChat (AIM): jbendotnet Skype: jon-bennett --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---