PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, February 13, 2022

[FIXED] Cakephp 3.0 ROOT variable gets set wrong

 February 13, 2022     cakephp-3.0     No comments   

Issue

After a stock install and creation of a basic controller, the environment variables are being set wrong.

For example, ROOT gets set as follows:

/var/www/html/appname/src//var/www/html/appname

In other words, the Apache webserver DocumentRoot is being appended to it.

Why?


Solution

What I learned is that if I specify the absolute path to the file in a controller, the Apache DocumentRoot gets appended to the ROOT variable. For example:

public function getFile() {
    // disable the default layout for the view
    $this->viewBuilder()->layout(false);
    $path = ROOT . '/file/file.txt';
    $this->response->file($path, array('download' => true));
    return $this->response;
}

The browser cannot find the file at location /var/www/html/app/src//var/www/html/app/src/file/file.txt

However the following works as expected:

public function getFile() {
    // disable the default layout for the view
    $this->viewBuilder()->layout(false);
    $path = '/file/file.txt';
    $this->response->file($path, array('download' => true));
    return $this->response;
}

The ROOT location seems to get automatically pre-prended to the path I have set above. I was not aware of this and haven't read anything about it in the documentation, so I am still not sure why it works this way.



Answered By - geofrey rainey
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing