Jump to content

Recommended Posts

Posted

i am relatively new at php coding, i have the basics down though.

 

i am writing a file for me and my freind who also run a website. we both want comments/ratings boxes and none of them that we found fit what we wanted, so i decided to make one myself.

 

i don't know if its a problem with my coding or permissions with heliohost, but i want the code to open a text document for all the comments.

 

this is the error i get:

Warning: fopen(/coments.txt) [function.fopen]: failed to open stream: Permission denied in /home/bmanp/public_html/learning/commentsbox/comments.php on line 5

 

<?php
//below put the file on the server
$location="/coments.txt";
$avrgrtng=0;
$file=fopen($location,"r");
?>

this is the coding i have so far, the only lines that need to be paid attention to are 3 and 5

 

in 3 we allow the webmaster to put in the location of the text file to be used for the comments box.

 

in 5 we load the file so the script can read it

 

so the question is: am i opening the file wrong /where would the text file be if it were in www.mysite.com/mysubdirectory/ or is there a conflict with permissions on the server (please note for any fixes for the permissions, this will be a code that will be copy&pasted on multiple pages on my site.

Posted

In Linux, the root of the filesystem (sort of like C:\ in Windows) is "/". So when you write "/coments.txt", you are trying to access outside your location and you get a permission denied error.

 

You need to set $location to "./comments.txt". Hope that helps :)

Posted

I don't use Linux(but I'm planning on learning) but as far as i understand ./ is the same as linking to a file that is in the current directory such as for a link in html it would be /.

 

thank you

 

One more question, how would I access a file that is in a different directory on my site, say if I kept all the text files in one directory, say www.mysite.com/comments/?

Posted

You can go back up a directory with "../". So if you're executing www.mysite.com/index/index.php and you need to access www.mysite.com/comments/comments.txt, then your path would be "../comments/comments.txt". You can also just write an absolute path, like /home/yourheliohostusername/public_html/comments/comments.txt.

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
×
×
  • Create New...