Page 1 of 1

Problem with writing form contents to file

Posted: Sat Nov 07, 2009 3:18 pm
by ramya4myself
Hello,

I am writing two php scripts one for form and other one to write the values of a form using php into a file and also print the values on the another html page. I dont know why it is not writing into the file but if I print the form values in the script, that is getting printed on the html page. The fopen should create the file but until I set the permissions manually it shows the error, " permission denied" on the html page. I even checked the path of the file. When I Execute the file, it directly goes to the else clause, "Cannot write to the file". Could anyone please help me with this. I am using this code for writing to the file:

Code: Select all

$filename="test.txt";
 
if(is_writable($filename)){
if(!$fp = fopen($filename,'a')){
echo "cannot open file($filename)";
exit;
}
if($fp!=null)
{
fwrite($fp,$name);
fwrite($fp,$date);
fwrite($fp,$platform);
fwrite($fp,$browser);
fwrite($fp,$comments);
}
fclose($fp);
}
else
{
echo "Cannot write to the file";
}
 
Thanks

Ramya

Re: Problem with writing form contents to file

Posted: Sat Nov 07, 2009 6:23 pm
by ramya4myself
I even tried by editing the code but I could not succeed in writing to the file. I says permission whenever I use this.

Code: Select all

$filename="test.txt";
 $fp = fopen($filename,'a')
 
 if($fp!=null)
 {
 fwrite($fp,$name);
 fwrite($fp,$date);
 fwrite($fp,$platform);
 fwrite($fp,$browser);
 fwrite($fp,$comments);
 }
 fclose($fp)
;

thanks

Re: Problem with writing form contents to file

Posted: Sun Nov 08, 2009 1:17 pm
by ramya4myself
Thanks.
I could solve writing into a file but I want the filename in a particular directory like PHP/Peter.txt. This is not happening even though I set the permissions of the file and the directory. It displays an error "fopen cannot open directory: Is a directory /PHP/Peter.txt ". Could anyone please help me with this. I am using putty server in Window XP.