Jump to content

Ensuring Directory has read and writer permissions for everyone


DirkDiggler
 Share

Recommended Posts

I am installing a simple Hit Counter and I get the following error

 

"Warning: file_put_contents(hitcount.txt) [function.file-put-contents]: failed to open stream: Permission denied in..."

 

I realize this error is because I do not have the correct permissions set, and I cannot seem to get the chmod() function right to accomplish this.

 

The current code below gets both the above error and this error:

 

"Warning: chmod() [function.chmod]: Operation not permitted in..."

 

HitCounter.php is the page that is running and getting an error. This file is in the "../Chapter.05/Projects" directory of the server. How can I give "/Projects" read and write permissions for everyone??

 

Thanks!

<!DOCTYPE html><html><head><title>Hit Counter</title></head><body><?phpchmod("/home/ca86_22/public_html/Chapter.05/Projects",0666);$CounterFile = "hitcount.txt";if (file_exists($CounterFile)) {	$Hits = file_get_contents($CounterFile);	++$Hits;	// if $CounterFile exists, retrieves $Hits value				// and increments by 1} else $Hits = 1;echo "<h1>There have been $Hits hits to this page.</h1>n"; //displays # of hitsif (file_put_contents($CounterFile, $Hits)) //updates value in hitcount.txt file//file_put_contents opens the file if it already exists =OR= creates the file if it doesn't	echo "<p>The counter file has been updated.</p>n";?></body></html>
Edited by DirkDiggler
Link to comment
Share on other sites

If you don't have permission to write to the file, then you also don't have permission to change the mode. You need to do it with a user that has permission. Your FTP user might have permission, so you can log in via FTP and set the permissions for the directory and files to allow PHP's user to write to them.

Link to comment
Share on other sites

I'm not sure if it's possible to fix it through PHP or not, but you can try change the chmod with your FTP-CLIENT.

For instance, if you use FlashFXP, right click on the folder -> Attributes (CHMOD) -> *your setting*.

Edited by Petrucho
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...