cakephp disable routing for specific URLs - cakephp

I have a CakePHP 1.3.10 app which I'm trying to make it do the following:
I want to embed a mp3 file in some views, using Google's reader flash audio player. If I put the mp3 file in the webroot directory of my app, there's no problem. However, I would like to have those files in a directory called AUDIO at the same level of my app directory. Like:
[public_html]
[app]
[cake]
[AUDIO]
...
The problem is that if I put my mp3 files there, when I link to them from my view, Cake looks for the controller audio, which doesn't exist, instead of just linking my file. I believe this has something to do with routing, so I was wondering if I can disable automatic routing for a specific folder (**audio in this case).
I want to do this in this way because in the future I might have to access those mp3 from other websites, so I don't want to put them deep into cake's directory system.
Thanks so much in advance for any tips!

Files that should be directly served by the web server without going through Cake should be put in the /app/webroot directory. You can create such a /webroot directory in plugins as well (see here), which technically will use routing, but behaves the same as the general webroot directory.
If you place them anywhere else you're going against Cake conventions, which I wouldn't recommend. Not because it's not possible, you're just making your life harder than it needs to be. You can edit the /app/webroot/.htaccess file to rewrite certain URLs to wherever you stored your files or use Media Views (as pointed out by #Ivo) if you really want to do this.

CakePHP won't be able to automatically find files in folders that it doesn't know about.
I'd suggest using Media Views to serve files from a custom directory.
If you want them to be freely downloadable, you can do this using MediaView also, or put them in a custom folder inside webroot. You'll need to include that folder in paths etc, though.

Related

How can I create an add folder functionality to my React CMS application?

Click here to see a picture of what I mean
I haven't tried anything yet because I'm not sure how to even approach this problem. I'm not even sure what to Google. I do, however, have a pretty good handle on React. Thanks!
Update: The folders will not be storing files, just hyperlinks.
You need to model the problem space first. i.e. models for folders, and files. Each having properties (name, etc.) and associations (folders can have many files and subfolders).
To store the physical files you can use a third-party service like Amazon S3.
This would get you started at least.

Dart: Accessing a resource out side the project|web/ directory

I have a web-app(browser based) which needs to access a folder full of icons that resides outside the web folder.
This folder MUST be outside the web folder, and would ideally exist outside the project folder all together
however, when specifying the path to the folder neither "../" or making use of a symlink will work
when the page attempts to load the image I always get
"[web] GET /Project|web/icons/img.png => Could not find asset Project|web/icons/img.png."
however I set the image source to "../icons/img.png"
how can i get dart to access this file properly
PS: I attempted a symlink to another part of the filesystem (where the images would be kept ideally) however this did not work either.
The web server integrated into DartEditor or pub serve only serves directories that are added as folders to the files view. When you add the folder to DartEditor you should be able to access the files. This is just for development.
You have also to find a solution for when you deploy your server app. It would be a hazardous security issue when you could access files outside the project directory. Where should the server draw the line? If this would be possible your entire server would be accessible to the world.
Like #Robert asked, I also have a hard time imaging why the files must not be in the project folder.
If you want to reuse the icons/images between different projects you could create a resource package that contains only those images and add them as a dependency to your project.
If you want a better answer you need to provide more information about your requirements.
If you wrote your own server (by using the HttpServer class) it may be possible to use the VirtualDirectory to server your external files.
Looking at look the dartiverse_search example may give you some ideas.
You could put them in the lib directory and refer to them via /packages/Project/...
Or in another package, in which case they would be in a different place in the file system. But as other people have said, your requirement seems odd.

I have a huge music archive on a remote server. How can I set up a page that lets people interact with it?

What I want to have is some sort of file tree that people can interact with and download songs or folders of songs. I kinda got started with a file listing PHP script (which you can see here) but it requires me to copy the same index.php to every individual folder. I would be okay with this if I knew how to copy the same file to every subdirectory in the archive.
What do you guys think? Any ideas?
What you do is to use your webserver to browse the file hierarchy. But what you want is to use your script (the index.php). So instead of creating links that point to a deeper place in your file system, create links that point to your index.php, but add a parameter that tells the script the (relative) folder. Beware that you have to verify that only files can be shown that you actually want to make public (i.e. no files above your "entry" directory).

Share resources among multiple CakePHP webroots on Windows / IIS?

I've got a CakePHP install running six different web sites, each with their own webroot. All of the base code is the same (controllers, models, etc.), just the css, images, js and so forth are split into the separate webroots (app/webroot, app/webroot_second_site, app/webroot_third_site, etc.)
My question is: Is there a way to share common resources among the webroots? So we don't have six different copies of TinyMCE and jQuery cluttering up our project, and more importantly to me, so that we can make a change in a common CSS file instead of having to copy/paste a change across six different sites' folders?
If these sites were running on a Linux box, I think it could be fairly easily accomplished with a symlink from each of the webroots to a common folder higher up in the directory tree, but we're running Windows Server 2003 / IIS 6. Any suggestions?
Turns out you can do directory symlinks in NTFS file systems. Or at least close enough for practical purposes. "NTFS Junctions" will work for what you want.
Grab the Sysinternals "Junction" program for a simple command-line program to create/delete these junctions.
Then you can link whatever common directories you need to a single master directory.
For example, if you have
webroot1/
webroot2/
webroot3/
each with their own "js/" directory, then you could create
webroot_common/js/
and then symlink... er, "create junctions" to that new directory like so:
junction webroot1/js/common webroot_common/js
junction webroot2/js/common webroot_common/js
junction webroot3/js/common webroot_common/js
(yes, the "junction" program takes its inputs backwards from Linux "ln -s")
Then you can put whatever common js files you need, like jQuery, in that common folder, and leave any site-specific js files in "webrootX/js".
You could make a static server. Add a DNS entry to something like static.yoursite.com. Link to those files from your other sites -- probably you could just modify the HTML helper so that it will automatically create links to the other domain.
This can help with performance, because you can run something like nginx to serve these static files. It will also parallelize the resource retrievals -- most browsers will allow 2 connections to a given server, so the static stuff competes with those connection resources that are needed by the dynamic stuff. In essence, the user will start 2 connections to your dynamic stuff as well as 2 connections to the static resources.
Works pretty well IME.
This will work. You will need to redefine the directories for a windows server, but you will understand it well enough.
First, put your APP and CAKE directories a level above the public_html.
/var/www/app
/var/www/cake
Make sure that the folder cake has all of the cake folders in it (cake, vendors, etc.)
Point your sites to their public_html directories.
/var/www/html/site1
/var/www/html/site2
The webroot content will sit in each of the public_html directories. Now, modify your index.php file in each of the webroots to point to the same app:
if (!defined('ROOT')) {
define('ROOT', DS.'var'.DS.'www'.DS.'app');
}
if (!defined('APP_DIR')) {
define('APP_DIR',dirname('app'));
}
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
define('CAKE_CORE_INCLUDE_PATH', DS.'var'.DS.'www'.DS.'cake');
}
Make sure that rewrite is turned on of course. Then it will all run off the same code but use the webroot where the index.php is being served from.

CakePHP cache control for asset files (images, CSS, etc)

What's the best way to use CakePHP to control the Expires headers for image and CSS files?
My host unfortunately doesn't support mod_expires or mod_headers, so I can't simply set these values in an .htaccess file. Right now there's no cache control for my files and a lot of unnecessary requests are made.
What's the most elegant way to pipe requests for asset files through Cake and set the appropriate headers via header()?
I guess the best, not even necessarily Cake-specific way, is to create a script in /webroot that adds the headers, then use .htaccess directives to pipe requests for ./css/* and ./img/* through that file. I was just hoping there might be some functionality like this built into Cake already. :)
I would suggest writing a helper which takes the filename and then returns a URL to a PHP script which fetches the file and adds the necessary header. You can see an example of a basic helper here: http://bakery.cakephp.org/articles/view/image-resize-helper

Resources