|
I'm a newer in cakephp. I want to build a download system with cake. I host the file at WWW_ROOT.DS.'upload'.DS.$filename (eg:www.aaa.com/upload/aaa.txt). I use the code $this->redirect("/upload/$file_name"); to download the file. But the system told me: Missing controller You are seeing this error because controller UploadController could not be found. Fatal: Unable to load controller UploadController Fatal: Create Class: <?php class UploadController extends AppController { var $name = 'Upload'; } ?> in file : app\controllers\upload_controller.php I know something wrong in my code. I mean upload is a dir not a controller. What can I do? Help me. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to [hidden email] To unsubscribe from this group, send email to [hidden email] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
Why instead of doing a redirect to the file you handle it the Cake way? For example, build an action called download in a controller called downloads. Something like: <?php class DownloadsController extends AppController { var $name = 'Downloads'; var $downloadPath = WWW_ROOT . DS . 'upload'; function download($file) { $filePath = $this->downloadPath . DS . $file; // Check against path injection if (preg_match('/^[A-Za-z0-9_\-\.]*$/', $file) && is_readable($filePath)) { $size = @filesize($filePath); if (!headers_sent()) { if ($size > 0) { header('Content-length: ' . $size); } header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.$file); } readfile($filePath); exit; } return $this->redirect('/'); } } ?> Then when you build links to your files you do them like: <a href="/downloads/download/my_file.txt">Download</a> Or you can also add the following route to your app/config/routes.php file: $Route->connect('/download/*', array('controller' => 'downloads', 'action' => 'download')); And then build links like: <a href="/download/my_file.txt">Download</a> -MI --------------------------------------------------------------------------- Remember, smart coders answer ten questions for every question they ask. So be smart, be cool, and share your knowledge. BAKE ON! -----Mensaje original----- De: [hidden email] [mailto:[hidden email]] En nombre de rainbow686 Enviado el: Domingo, 03 de Diciembre de 2006 10:57 p.m. Para: Cake PHP Asunto: what can I do, when I want download files form cake build system. I'm a newer in cakephp. I want to build a download system with cake. I host the file at WWW_ROOT.DS.'upload'.DS.$filename (eg:www.aaa.com/upload/aaa.txt). I use the code $this->redirect("/upload/$file_name"); to download the file. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to [hidden email] To unsubscribe from this group, send email to [hidden email] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
In reply to this post by Sun Bin
That usually means you got the file path wrong, as any path to a real file in your web root does not get "eaten" by Cake. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to [hidden email] To unsubscribe from this group, send email to [hidden email] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
In reply to this post by Mariano Iglesias
Oh, thank a lot, I will try it. I don't know how download the file with the Cake way, and I didn't find the infomation is the Cake's doc, so can you tell me where can I get those information? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to [hidden email] To unsubscribe from this group, send email to [hidden email] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
That's what I just gave you :) -MI --------------------------------------------------------------------------- Remember, smart coders answer ten questions for every question they ask. So be smart, be cool, and share your knowledge. BAKE ON! -----Mensaje original----- De: [hidden email] [mailto:[hidden email]] En nombre de rainbow686 Enviado el: Lunes, 04 de Diciembre de 2006 12:20 a.m. Para: Cake PHP Asunto: Re: what can I do, when I want download files form cake build system. Oh, thank a lot, I will try it. I don't know how download the file with the Cake way, and I didn't find the infomation is the Cake's doc, so can you tell me where can I get those information? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to [hidden email] To unsubscribe from this group, send email to [hidden email] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
In reply to this post by Sun Bin
fyi, only the following physical directories are accessible in cakephp: app/webroot/files -> mapped as {URL}/files app/webroot/img -> mapped as {URL}/img app/webroot/css -> mapped as {URL}/css app/webroot/js -> mapped as {URL}/js if, say, you use other directories such as {URL}/custom_dir, that directory will be mapped out as a controller name (CustomDirController), unless otherwise specified in app/config/routes.php i would suggest that i you want to make a download system, you should use the app/webroot/files directory to store your uploaded files --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to [hidden email] To unsubscribe from this group, send email to [hidden email] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
On Dec 5, 9:55 am, "Evan" <[hidden email]> wrote: > fyi, only the following physical directories are accessible in cakephp: Hi Evan, That's a bit misleading. If you create on your server /CustomDir/something.txt, you can access it with the url /CustomDir/something.txt; if you try to just access the folder, that will be handled by cake because the url doesn't map to a file. Moreover, that's the same for any and all folders under where cake is installed (if you have mod_rewrite enabled), there is nothing magic that prevents cake form capturing incorrect files/img/css/js urls; If the url does not relate to a phycical file (either directly, or after being rewritten to the webroot if appropriate), cake will be put into action, compare: http://www.cakephp.org/img/donate/cake100donate.png with http://www.cakephp.org/img/NotHere.anything BTW if you put files in the webroot/files folder, that means that if you know the url you can download the file, which may not be what is desired (I don't know). If you want to control access to files, it's much better to follow an approach similar to how Mariano has suggested (but with the files inaccessible directly via a url if you want to protect them), and serve the files to the user. HTH, AD7six Please note: The manual/bakery is a good place to start any quest for info. The cake search (at the time of writing) erroneously reports less/no results for the google group. The wiki may contain incorrect info - read at your own risk (it's mainly user submitted) :) You may get your answer quicker by asking on the IRC Channel (you can access it with just a browser here:http://irc.cakephp.org). --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to [hidden email] To unsubscribe from this group, send email to [hidden email] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~--- |
| Powered by Nabble | Edit this page |
