0

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

5 Answers 5

1

You may need to change the permissions as an administrator. Open up terminal on your Mac and then open the directory that etlLOG.txt is located in. Then type:

sudo chmod 777 etlLOG.txt

You may be prompted for a password. Also, it could be the directories that don't allow full access.

OR

PHP

chmod : Attempts to change the mode of the specified file to that given in mode.

chmod

Sign up to request clarification or add additional context in comments.

3 Comments

777 might be a little overkill I'd suggest 644 or 664. Anyway +1 ;)
And if the file didn't exist? fopen with +w should create it so he might havetochange the directory permissions too/instead
Well I am not the admin and I cannot make any permission change
1

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

Comments

0

If you are running WAMP on windows

1) login as an administrator

2) Install wamp

3) Download subinacl.exe from microsoft:

4) grant permissions to the regular user account to manage the WAMP services: (subinacl.exe is 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) logout and log back in as the user. They should now be able to launch the WAMP taskbar application and control the WAMP service.

Comments

0

My guess is that PHP is trying to create the file at 'C:\WINDOWS', so the solution wouldn't be to set permissions there.

I would suggest you use a specific location, example: create a folder at the same location as your php script and use it to create the files:

$filePath =  dirname(_FILE_) . "/temp_vars/etILOG.txt";
$file = fopen($filePath ,"w+");

Kind regards,

Comments

0

The code you are running is trying to create the etlLOG.txt in the same folder as your PHP script. You need to give Full Permission to your IUSER_ account on the E:\Users\george folder.

If you do not know how you can browse the following links

http://technet.microsoft.com/en-us/library/bb727008.aspx

http://www.wikihow.com/Change-File-Permissions-on-Windows-7

How to set 777 permission on a particular folder?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.