PHP Classes


Recommend this page to a friend!

      Comment  >  All threads  >  cssdir  >  (Un) Subscribe thread alerts  
Summary:had to hard code the path for some reason
Author:Randy Ahn
Date:2006-09-04 05:15:47
Update:2006-09-05 04:59:57


  1. cssdir   Reply   Report abuse  
Randy Ahn - 2006-09-04 05:15:47
This drove me crazy. For some reason, in test_comment.php, $cssdir kept throwing this error: Warning: fopen(../examplecomment.css): failed to open stream: Permission denied in /home/user/public_html/comments/class_comment.php on line 206

Warning: fwrite(): supplied argument is not a valid stream resource in /home/user/public_html/comments/class_comment.php on line 207

COMMENT::install() Can not write CSS file [../examplecomment.css]

I had to actually hard code the path into line 206 -- looked as if this->$cssdir had some other value than what I declared on line 23? Anyway, hard coding the path ran cleanly and the script then installed the correct table, fields, and css.

  2. Re: cssdir   Reply   Report abuse  
Peter Klauer - 2006-09-04 06:04:00 - In reply to message 1 from Randy Ahn
On some servers, writing is not allowed and you can not change this. In that cases Comment can not write and can not install. But in your case writing was possible after "hard coding".

I am very sorry to tell you: "There must have been an error in your coding"

Some errors are hard to see. I have already made thousands and I still do so, but I am very trained in seeing errors. Would you kindly submit the code that did not work?

  3. Re: cssdir   Reply   Report abuse  
Randy Ahn - 2006-09-04 16:58:15 - In reply to message 2 from Peter Klauer
Thanks Peter:

When I'm evaluating a new class, I tend to place all files within the same directory. So the only change I made to class.comment.php was on line 23:
var $cssdir = './'; to point to the current directory. This caused test_comment.php to throw the error, so I tried other directories, tried an string empty, created a css subdirectory, etc. I completely opened up permissions on the current directory and parent directory to 777. I also checked that the scripts were owned by nobody.

Then on line 206, I commented out "$this->cssdir" and replaced it with my path, and it worked!
$handle = fopen( /*$this->cssdir*/'./'.$this->code_for.'comment.css', 'w' );

I thought I must have made a mistake somewhere, so I untarred the package again and went through the steps a second time with the same result. I still think it's something silly that I'm doing wrong. I appreciate your help and this great class.

  4. Re: cssdir   Reply   Report abuse  
Peter Klauer - 2006-09-04 18:03:33 - In reply to message 3 from Randy Ahn
Changing line 23 does not work, because comment::cssdir will be overwritten from the constructor.
Then you changed row 206 and hard coded your css-path instead of $this->cssdir ?

Not great at all.

You have changed a class simply to hardcode a parameter which could easily be changed from outside the class: Big Mistake. Next time, when I upload a new version and you happily upgrade then Comment will again not work anymore. If you copy this class to a new project, it will not work anymore, because the path is not the same. You will be angry with me for distributing such a %$&. You will have forgotten that you hardcoded your path into it.

- - - - - - - - - - - - - -

The 4th argument of the "new comment()" constructor is the path to set. I strongly recommend to reload the class, not change it and put the
css path argument

a) as 4th arg of "new comment()" or
b) after $comment = new comment(...);
$comment->cssdir = 'my hard coded path here';

  5. Re: cssdir   Reply   Report abuse  
Randy Ahn - 2006-09-04 19:40:02 - In reply to message 4 from Peter Klauer
thanks Peter. it was something silly now wasn't it? I looked over the page and passed right over the params in the constructor!

  6. Re: cssdir   Reply   Report abuse  
Peter Klauer - 2006-09-05 04:59:57 - In reply to message 5 from Randy Ahn
In our office we say:

The error is sitting in front of the monitor.

(Because we still make errors, too.)