DirkDiggler Posted March 21, 2014 Share Posted March 21, 2014 (edited) 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 March 21, 2014 by DirkDiggler Link to comment Share on other sites More sharing options...
justsomeguy Posted March 21, 2014 Share Posted March 21, 2014 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 More sharing options...
Petrucho Posted March 21, 2014 Share Posted March 21, 2014 (edited) 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 March 21, 2014 by Petrucho Link to comment Share on other sites More sharing options...
DirkDiggler Posted March 21, 2014 Author Share Posted March 21, 2014 I use winSCP and I have no idea how to do this Link to comment Share on other sites More sharing options...
Petrucho Posted March 21, 2014 Share Posted March 21, 2014 Look here , you might find it helpful. Link to comment Share on other sites More sharing options...
DirkDiggler Posted March 21, 2014 Author Share Posted March 21, 2014 I have been able to get the counter to work, but that error still occurs... "Warning: chmod() [function.chmod]: Operation not permitted in..." Link to comment Share on other sites More sharing options...
Petrucho Posted March 21, 2014 Share Posted March 21, 2014 After changing the folder chmod, you have no reason to keep using the chmod() in your code. Remove it, then it should work the way you wanted. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now