dimanche 19 avril 2015

How to create a file from controller

I'm trying to save a file from a controller. It doesn't work using fopen and I'm unable to get the error message. Is there a way to do this or a absolutely need to use the filesystem bundle? And is there a way to understand the error? I used a try/catch blog with no luck. The code I'm using is really simple:



$file = $this->get('request')->server->get('DOCUMENT_ROOT').'/myfile.txt';
$fp = fopen($file, 'w');
fwrite($fp, 'file content');
fclose($fp);

Aucun commentaire:

Enregistrer un commentaire