Can open and read a file but can't chmod or write to it!
Posted: Tue Dec 29, 2009 6:15 am
Hi everyone.
I'm getting totally frustrated trying to open and write data to a text file.
Here's a section of the code I've been working with. I get different results depending on whether I try to open the file with "r" or "a".
Here's the code with a "r" open:
Using this code, these are the messages I get.
FILE CONTENTS = text inside file
The file formdata.txt does not exist.
Warning: chmod(): No such file or directory in /home/content/d/o/n/dondean/html/Success/form/completion.php on line 214
Unable to change chmod
As you can see, the file read was successful.
The contents of the file were: "text inside file".
Yet chmod tells me the file does not exist.
Now if I change the "r" to "a", I get these messages:
Warning: fopen(http://www.mywebsitename.com/Success/fo ... rmdata.txt): failed to open stream: HTTP wrapper does not support writeable connections. in /home/content/d/o/n/dondean/html/Success/form/completion.php on line 204
Unable to open file!
My host is "Godaddy" on a Linux server. I've changed the permissions on the file and the directory to web user "read,write and execute".
I've also tried running the code without the file existing, to see if it would be created with the fopen statement, but it does not.
Can anyone give me some help at to what the problem is?
Thanks
I'm getting totally frustrated trying to open and write data to a text file.
Here's a section of the code I've been working with. I get different results depending on whether I try to open the file with "r" or "a".
Here's the code with a "r" open:
Code: Select all
<?php
if ($_POST['submitbutton'] == "Submit this Form")
{
$file_name = "http://www.mywebsitename.com/Success/formdata/formdata.txt" or exit(" <br /> No file");
$open_file = fopen($file_name, "r") or exit(" <br /> Unable to open file!");
$display_contents = fread($open_file,17);
echo " <br /> FILE CONTENTS = " . $display_contents;
if (file_exists($open_file))
echo " <br /> The file formdata.txt exists. <br /> ";
else
echo " <br /> The file formdata.txt does not exist. <br /> ";
chmod($open_file,0777) or exit(" <br /> Unable to change chmod");
fclose($open_file);
}
?>FILE CONTENTS = text inside file
The file formdata.txt does not exist.
Warning: chmod(): No such file or directory in /home/content/d/o/n/dondean/html/Success/form/completion.php on line 214
Unable to change chmod
As you can see, the file read was successful.
The contents of the file were: "text inside file".
Yet chmod tells me the file does not exist.
Now if I change the "r" to "a", I get these messages:
Warning: fopen(http://www.mywebsitename.com/Success/fo ... rmdata.txt): failed to open stream: HTTP wrapper does not support writeable connections. in /home/content/d/o/n/dondean/html/Success/form/completion.php on line 204
Unable to open file!
My host is "Godaddy" on a Linux server. I've changed the permissions on the file and the directory to web user "read,write and execute".
I've also tried running the code without the file existing, to see if it would be created with the fopen statement, but it does not.
Can anyone give me some help at to what the problem is?
Thanks