Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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



1.4k
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...



5.0k
edited Jul '14

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