Been using this code:
їphp]
$fp = fopen ("file.php", "w");
$Line1 = "this is a testn";
$Line2 = "test for line 2n";
echo $Line1;
echo $Line2 ;
fputs($fp, "this is a testn");
fputs($fp, "test for line 2n");
ї/php]
And I keep getting these errors: (regarding the permission denied, I"ve changed teh permission to 777. But still gives me that.
Warning: fopen("file.php", "w") - Permission denied in /home/account/public_html/template_test3.php on line 13
this is a testntest for line 2n
Warning: fputs(): supplied argument is not a valid File-Handle resource in /home/account/public_html/template_test3.php on line 20
Warning: fputs(): supplied argument is not a valid File-Handle resource in /home/account/public_html/template_test3.php on line 21
?>
errors from fopen, fputs
Moderator: General Moderators
are you sure you chmod'd the right "file.php"?
are you sure the path is correct?
what happens if you do...
include "file.php";
(type some text in it first)
does it find the file?
when it says "supplied argument is not a valid File-Handle resource " it means that no value has been assigned to $fp... i.e. couldn't open the file for writing.
also the "dir." that "file.php" is in might also have to be chmod 777
are you sure the path is correct?
what happens if you do...
include "file.php";
(type some text in it first)
does it find the file?
when it says "supplied argument is not a valid File-Handle resource " it means that no value has been assigned to $fp... i.e. couldn't open the file for writing.
also the "dir." that "file.php" is in might also have to be chmod 777
hmm...some good questions here. Actaully the current script is template_test2.php as you can see form teh error. Tha is actaully th file I am giving the permissions. Put I guess I'd need an actual "file.php" tht I chmod or as you say chmod the directory.
Regarding the "supplied argument is not a valid File-Handle resource "It would seem that I've created a bit of a catch22 for myself. Need the file.php to be there and it can't create it.
OK, from a previous example I was reading from someone else teh example was given to use fopen as:
$fp = fopen ("http://www.domain.com/file.php", "w");
Which gave me:
Warning: fopen("http://www.npiflorida.com/file.php", "w") - Success in /home/account/public_html/template_test3.php on line 13
Why would I get a success waring?
Regarding the "supplied argument is not a valid File-Handle resource "It would seem that I've created a bit of a catch22 for myself. Need the file.php to be there and it can't create it.
OK, from a previous example I was reading from someone else teh example was given to use fopen as:
$fp = fopen ("http://www.domain.com/file.php", "w");
Which gave me:
Warning: fopen("http://www.npiflorida.com/file.php", "w") - Success in /home/account/public_html/template_test3.php on line 13
Why would I get a success waring?
OK it seems to be working by creating the file.php then writing to it. However in the statement:
$fp = fopen ("file.php", "w");
Doesn't the "w" make it write the "file.php" if it doesn't exist? I checked the directory and chmod 777 was in place.
The ability to write the file if it doesn't exist is pretty important because this script will be used to write a file that doesn't exist and the name of the file wil be entered in the form that will create it when submitted.
$fp = fopen ("file.php", "w");
Doesn't the "w" make it write the "file.php" if it doesn't exist? I checked the directory and chmod 777 was in place.
The ability to write the file if it doesn't exist is pretty important because this script will be used to write a file that doesn't exist and the name of the file wil be entered in the form that will create it when submitted.
- gite_ashish
- Forum Contributor
- Posts: 118
- Joined: Sat Aug 31, 2002 11:38 am
- Location: India
hi,
from php man:
this can happen if the directory in which this file is getting created is not having proper rights for php to do so. ie if one want to create file "user1.txt" in /home/www/site.com/userdata/user1.txt, the "userdata" directory should have rights for php.
either set like this of "chmod 777 userdata" will always work !
from php man:
i think u r script is trying to create the file, because the script is giving the error:'w' - Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.
Warning: fopen("file.php", "w") - Permission denied in /home/account/public_html/template_test3.php on line 13
this can happen if the directory in which this file is getting created is not having proper rights for php to do so. ie if one want to create file "user1.txt" in /home/www/site.com/userdata/user1.txt, the "userdata" directory should have rights for php.
my web server is running as nobody:nobody for user:group.drwxr-xr-x 2 nobody nobody 4096 Sep 7 20:09 userdata
either set like this of "chmod 777 userdata" will always work !
CHMOD file.php to 777.
Use this
Use this
Code: Select all
<?php
$fp = fopen("file.php","a");
?>Code: Select all
'a+' - Open for reading and writing; place the file pointer at the end of the file. If the file does not exist, attempt to create it.