PHP Write variable to txt file
I am trying to get a variable from a query string and write it to a text file. I tried like this:
<?php
$content=( $_GET['var'] );
echo $content;
$file = fopen("etlLOG.txt","w+");
echo fwrite($file,$content);
fclose($file);
?>
I am getting the following errors:
Warning: fopen (etlLOG.txt) [function.fopen]: failed to open stream: permission denied at E: \ Users \ george \ listener.php on line 8
Warning: fwrite () argument: the supplied argument is not a valid stream resource in E: \ Users \ george \ listener.php on line 9
Warning: fclose (): the argument provided is not a valid thread resource in E: \ Users \ george \ listener.php on line 10
source to share
You may need to change administrator rights. Open a terminal on your Mac and open the directory where the etlLOG.txt file is located. Then enter:
sudo chmod 777 etlLOG.txt
You may be prompted for a password. In addition, these may be directories that do not allow full access.
OR
PHP
chmod . An attempt was made to change the mode of the specified file to the mode specified.
source to share
If you are using WAMP for Windows
1) log in as administrator
2) Install wamp
3) Download subinacl.exe file from Microsoft:
4) grant permissions for normal user account to manage WAMP services: (subinacl.exe is located in C: \ Program Files (x86) \ Windows Resource Kits \ Tools)
subinacl / SERVICE \ MachineName \ wampapache / GRANT = domainname.com \ username = F subinacl / SERVICE \ MachineName \ wampmysql / GRANT = domainname.com \ username = F
5) log out and log in as a user. They will now be able to launch the WAMP taskbar application and manage the WAMP service.
source to share
I am assuming PHP is trying to create a file in 'C: \ WINDOWS', so the solution will not set permissions there.
I suggest you use a specific location, for example: create a folder in the same location as your php script and use that to create files:
$filePath = dirname(_FILE_) . "/temp_vars/etILOG.txt";
$file = fopen($filePath ,"w+");
Respectfully,
source to share
The code you are using is trying to create an etlLOG.txt file in the same folder as your PHP script. You need to grant full permission to your IUSER_ account in the E: \ Users \ george folder.
If you don't know how you can view the following links
http://technet.microsoft.com/en-us/library/bb727008.aspx
source to share