Search code examples
phpfopenfwrite

PHP Write a variable to a txt file


I am trying to get a variable from the query string and write it to a text file. I have tried like this:

<?php
$content=( $_GET['var'] );
echo $content;
$file = fopen("etlLOG.txt","w+");
echo fwrite($file,$content);
fclose($file);
?> 

I get the following errors:

Warning: fopen(etlLOG.txt) [function.fopen]: failed to open stream: Permission denied in E:\Users\george\listener.php on line 8

Warning: fwrite(): supplied argument is not a valid stream resource in E:\Users\george\listener.php on line 9

Warning: fclose(): supplied argument is not a valid stream resource in E:\Users\george\listener.php on line 10


Solution

  • Well it appears that the web server does not have access to that file. So used ftp fopen provided the correct credentials and paths and finally i did managed to access and edit the file