Fw: [PEAR] is there anyone help me?
| From: | Mikko Yue | Date: | Mon, 15 Mar 2004 03:05:23 +0000 |
| Subject: | Fw: [PEAR] is there anyone help me? | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-11291@lists.php.net to get a copy of this message | ||
----- Original Message -----
From: "Matthias Nothhaft" <php@mahono.de>
To: "Mikko Yue" <mikkoyue@hotmail.com>
Cc: "pear_developing" <pear-general@lists.php.net>
Sent: Monday, March 15, 2004 9:29 AM
Subject: Re: [PEAR] is there anyone help me?
> Hi Mikko Yue, you wrote:
>
> > hey, there. I am a new user of pear. I was learning to use the pear class in my developing
> > these days. I wrote a userdefined class extends from pear, and in the deconstructor function I open
> > a file for write, but it told me an error of "Permission denied". but when I delete the
> > extends codes, it worked. Is there anyone help me?
> >
> > Regards.
> >
> > Mikko Yue
> could you please send a bit code with the problem,
> this would make it easier to find a nice answer ;-)
>
> regards,
> Matthias
>
> --
> PEAR General Mailing List (http://pear.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
hey, there. I have run the command "chmod 666 text.txt" and "chmod 777 <the
directory that obtained the text.txt>". my program and the result is following.
# cat test.php
<?php
include_once "PEAR.php";
class FileTest extends PEAR {
var $file;
var $content = "";
var $debug = true;
function FileTest($file) {
$this->PEAR();
if ($this->debug) {
print "<p><b>The constructor method of class FileTest is
running!</b></p>\n";
}
if ($file != "") {
$this->file = $file;
}
$this->output();
}
function _FileTest() {
if ($this->debug) {
print "<p><b>The deconstructor method of class FileTest is
running!</b></p>\n";
}
$string = "add a new line\n";
$this->input($string);
}
function output() {
if ($this->content == "") {
$this->read();
print $this->content;
}
}
function input($strings) {
if ($strings != "") {
$this->content .= $strings;
$fp = fopen($this->file, "w");
if (!is_resource ($fp)) {
return;
}
fwrite ($fp, $this->content);
fclose ($fp);
}
}
function read() {
if (file_exists ($this->file)) {
$fp = fopen($this->file, "r");
if (is_resource ($fp)) {
while (!feof ($fp)) {
$this->content .= fgets ($fp, 1024);
}
} else {
return;
}
fclose ($fp);
}
}
}
$file = "text.txt";
$afile =& new FileTest($file);
?>
the following is the result.
The constructor method of class FileTest is running!
this is the first line of the file text.txt
The deconstructor method of class FileTest is running!
Warning: fopen("text.txt", "w") - Permission denied in
/www/hr/www/mikko/test/test.php on line 42
the following is the result when I run the program as root in the console.
# php test.php
X-Powered-By: PHP/4.2.2
Content-type: text/html
<p><b>The constructor method of class FileTest is running!</b></p>
this is the first line of the file text.txt
<p><b>The deconstructor method of class FileTest is running!</b></p>
Best Regards.
Mikko Yue