Cakephp constants are not recognized when accessing a webroot file

Asked

Viewed 212 times

3

I was testing a simple upload system in my cakephp, so I referenced the img folder for these paths that the index.php of the root folder gives me. Only it was always giving error, saying that the path of the folder was wrong, and when I gave an echo in the variable, instead of returning me /var/www/html/app/webroot/, was returning me WWW_ROOT. Nor the . DS . is working. That is, my server is not recognizing the file constants index.php in the webroot folder.

$uploaddir = WWW_ROOT;
$uploadfile = $_FILES['userfile']['name'];
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir . DS . $uploadfile)) {
    echo "Arquivo válido e enviado com sucesso.\n";
} else {
    echo "Possível ataque de upload de arquivo!\n";
}

echo 'Aqui está mais informações de debug:';
print_r($_FILES);
echo $uploaddir;

NOTE: I made 2 files in the webroot folder itself, to have direct access, just to test. I just wanted to know, because my server doesn’t interpret this constant as it has to be, it has some access to it?

1 answer

1

As you said in a comment, your file is loose in webroot of the project, so it is accessed directly, without going through Cake. That way, nothing that is Cake’s is initialized, including the constants you quoted.

See the apache URL rewriting rules that are in webroot of Cake (attention to comments):

RewriteEngine On
# se o caminho corresponde a um diretório, acessa diretamente
RewriteCond %{REQUEST_FILENAME} !-d
# se o caminho corresponde a um arquivo, acessa diretamente
RewriteCond %{REQUEST_FILENAME} !-f
# caso contrário, chama o index.php passando o resto da URL como parâmetro
RewriteRule ^(.*)$ index.php [QSA,L]

That is, the file index.php of webroot, which is who initializes Cake, is only called if the URL does not match a directory or physical file below webroot.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.