Pergunta

My cakePHP application generates a simple text file inside the webroot directory.

I tried to access it by typing http://<my own domain>/simple.txt into my browser, but the application index page was shown up, not my text file.

How can I make this text file directly accessible? Please help me!

Foi útil?

Solução 2

First, add it as an extension to parse:

Router::parseExtensions('txt');

Then, create a connection route:

Router::connect('/simple.txt', array('controller' => 'examplecontroller', 'action' => 'simple');

Now you will control the output of http://yourproject.com/simple.txt inside simple() method inside examplecontroller and in simple.ctp view.

It's not the way exactly you specified, but it works for sure and it's done the "cake way"

Outras dicas

Only the webroot is web-accessible

Taking a guess, you have the following structure (or similar):

docroot
    app
        Config/
        Controller/
        Model/
        Plugin/
        Test/
        tmp/
        View/
        webroot/
    lib/
    ...
    simple.txt

That file simple.txt is inaccessible to a browser. The reason is, assuming mod_rewrite is enabled, that all requests are rewritten to be foo -> app/webroot/foo by the top-level .htaccess file.

To make the file accessible just put it in the webroot:

docroot
    app
        Config/
        Controller/
        Model/
        Plugin/
        Test/
        tmp/
        View/
        webroot/
            simple.txt <- moved
    lib/
    ...

Note that if this is the problem, you've got a development install - it would be a better idea to use a production install (make your webserver point at the webroot folder, not the root of your whole application).

these url ://simple.txt seems wrong to me. It should be like :

://yourhost/yourproject/simple.txt

I generally can access it in these manner on my local cake php project.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top