문제

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!

도움이 되었습니까?

해결책 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"

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top