Jump to content

phpcomments box problems


Recommended Posts

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.

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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/?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...