We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How read/write file from app directory

Hello, I cannot access a file.
Path to file: /app/resources/cities.txt

I'm trying use in indexController (indexAction)
return file_put_contents("cities.txt", $string);

I tried this path: /app/resources/cities.txt, /resources/cities.txt, resources/cities.txt, and cities.txt

How I can access this file?
Thanks



2.0k
Accepted
answer
edited Jul '14

Maybe this way, but it's a big hack:

$dir = dirname(__FILE__);
file_put_contents($dir."/../resources/cities.txt", $string);

Better solution is if you define main dirs in your config, and than you use that...



10.0k
edited Jul '14

Thank you, for the answer. How can I use the $config variable in controller? Set in DI?