PHP file writing
Moderator: General Moderators
-
anything000
- Forum Newbie
- Posts: 11
- Joined: Sat Nov 29, 2003 10:39 am
PHP file writing
Well, after searching for hours I can't figure it out.
Try this: http://phuckfonix.antiskewl.com/form.php
I get this error:
Warning: fopen(submitted.dat): failed to open stream: Permission denied in /home/virtual/site47/fst/home/phuckfonix/public_html/submittedforms.php on line 15
Warning: fwrite(): supplied argument is not a valid stream resource in /home/virtual/site47/fst/home/phuckfonix/public_html/submittedforms.php on line 16
Warning: fclose(): supplied argument is not a valid stream resource in /home/virtual/site47/fst/home/phuckfonix/public_html/submittedforms.php on line 17
Here's the part of the coding I think I'm having trouble with:
$file = "submitted.dat";
$newFile = fopen($file, 'a');
fwrite($newFile, $comments);
fclose($newFile);
Try this: http://phuckfonix.antiskewl.com/form.php
I get this error:
Warning: fopen(submitted.dat): failed to open stream: Permission denied in /home/virtual/site47/fst/home/phuckfonix/public_html/submittedforms.php on line 15
Warning: fwrite(): supplied argument is not a valid stream resource in /home/virtual/site47/fst/home/phuckfonix/public_html/submittedforms.php on line 16
Warning: fclose(): supplied argument is not a valid stream resource in /home/virtual/site47/fst/home/phuckfonix/public_html/submittedforms.php on line 17
Here's the part of the coding I think I'm having trouble with:
$file = "submitted.dat";
$newFile = fopen($file, 'a');
fwrite($newFile, $comments);
fclose($newFile);
-
anything000
- Forum Newbie
- Posts: 11
- Joined: Sat Nov 29, 2003 10:39 am
-
anything000
- Forum Newbie
- Posts: 11
- Joined: Sat Nov 29, 2003 10:39 am
Warning: chmod(): No such file or directory in /home/virtual/site47/fst/home/phuckfonix/public_html/new/submittedforms.php on line 13
Warning: fopen(submitted.dat): failed to open stream: Permission denied in /home/virtual/site47/fst/home/phuckfonix/public_html/new/submittedforms.php on line 16
Warning: fwrite(): supplied argument is not a valid stream resource in /home/virtual/site47/fst/home/phuckfonix/public_html/new/submittedforms.php on line 17
Warning: fclose(): supplied argument is not a valid stream resource in /home/virtual/site47/fst/home/phuckfonix/public_html/new/submittedforms.php on line 18
Is what I'm getting now.
The code is:
$doc_root = $HTTP_SERVER_VARS['DOCUMENT_ROOT'];
chmod ("$doc_root/new/", 0755);
$file = "submitted.dat";
$newFile = fopen($file, 'a');
fwrite($newFile, $comments);
fclose($newFile);
Warning: fopen(submitted.dat): failed to open stream: Permission denied in /home/virtual/site47/fst/home/phuckfonix/public_html/new/submittedforms.php on line 16
Warning: fwrite(): supplied argument is not a valid stream resource in /home/virtual/site47/fst/home/phuckfonix/public_html/new/submittedforms.php on line 17
Warning: fclose(): supplied argument is not a valid stream resource in /home/virtual/site47/fst/home/phuckfonix/public_html/new/submittedforms.php on line 18
Is what I'm getting now.
The code is:
$doc_root = $HTTP_SERVER_VARS['DOCUMENT_ROOT'];
chmod ("$doc_root/new/", 0755);
$file = "submitted.dat";
$newFile = fopen($file, 'a');
fwrite($newFile, $comments);
fclose($newFile);
-
d3ad1ysp0rk
- Forum Donator
- Posts: 1661
- Joined: Mon Oct 20, 2003 8:31 pm
- Location: Maine, USA
-
anything000
- Forum Newbie
- Posts: 11
- Joined: Sat Nov 29, 2003 10:39 am
-
anything000
- Forum Newbie
- Posts: 11
- Joined: Sat Nov 29, 2003 10:39 am
After reading chmod()
this is what I have:
But I have pretty much the same errors:
Warning: chmod(): No such file or directory in /home/virtual/site47/fst/home/phuckfonix/public_html/new/submittedforms.php on line 13
Warning: chmod(): No such file or directory in /home/virtual/site47/fst/home/phuckfonix/public_html/new/submittedforms.php on line 14
Warning: fopen(submitted.dat): failed to open stream: Permission denied in /home/virtual/site47/fst/home/phuckfonix/public_html/new/submittedforms.php on line 16
Warning: fwrite(): supplied argument is not a valid stream resource in /home/virtual/site47/fst/home/phuckfonix/public_html/new/submittedforms.php on line 18
Warning: fclose(): supplied argument is not a valid stream resource in /home/virtual/site47/fst/home/phuckfonix/public_html/new/submittedforms.php on line 19
What I'm trying to do anyways is write form input into a file.
this is what I have:
Code: Select all
<?php
chmod ("/new/submitted.dat", 0644);
chmod ("/new/submittedforms.php", 0644);
$file = "submitted.dat";
$newFile = fopen($file, 'a');
fwrite($newFile, $comments);
fclose($newFile);
?>Warning: chmod(): No such file or directory in /home/virtual/site47/fst/home/phuckfonix/public_html/new/submittedforms.php on line 13
Warning: chmod(): No such file or directory in /home/virtual/site47/fst/home/phuckfonix/public_html/new/submittedforms.php on line 14
Warning: fopen(submitted.dat): failed to open stream: Permission denied in /home/virtual/site47/fst/home/phuckfonix/public_html/new/submittedforms.php on line 16
Warning: fwrite(): supplied argument is not a valid stream resource in /home/virtual/site47/fst/home/phuckfonix/public_html/new/submittedforms.php on line 18
Warning: fclose(): supplied argument is not a valid stream resource in /home/virtual/site47/fst/home/phuckfonix/public_html/new/submittedforms.php on line 19
What I'm trying to do anyways is write form input into a file.
Code: Select all
chmod ("/home/virtual/site47/fst/home/phuckfonix/public_html/new/submitted.dat", 0644);
chmod ("/home/virtual/site47/fst/home/phuckfonix/public_html/new/submittedforms.php", 0644);You won't be able to the use the chmod() php function if you don't have right access to the file in the first place!
Ok, if you upload your scripts via ftp, check your ftp client for chmod (or permissions) and give the file Owner, Group and Other/World read/write access...
You have to do this to the file on the server on the client.
If you have shell access (which I would guess you don't)
# chmod a+rw /home/virtual/site47/fst/home/phuckfonix/public_html/new/submitted.dat
Ok, if you upload your scripts via ftp, check your ftp client for chmod (or permissions) and give the file Owner, Group and Other/World read/write access...
You have to do this to the file on the server on the client.
If you have shell access (which I would guess you don't)
# chmod a+rw /home/virtual/site47/fst/home/phuckfonix/public_html/new/submitted.dat
Open the site in your ftp program and do a dirinfo or whatever it's called in your program. You'll be able to see the owner/groups for files and folders. If there's anything there created by php, you'll see a different owner/group to files which you have ftp'd up to the server. Php is running under a different UID.
Php can't write files unless (a) the parent directory was created by php (and so has the owner/group which php runs under) or (b) the folder is CHMOD at 777 (which lets anything write there regardless of UID).
You don't want to leave a folder open on 777, so you can either:
(1) Use the php fn mkdir() to create writable folders with the php owner/group
(2) Or you can open it up the folder to 777 with your ftp program, write the file with php, and then CHMOD the folder back to 755. The file you just wrote has the php owner/group and so php can write to it again later even if the parent directory has a different owner group and is CHMOD 755. Of course, now you can't write NEW files there with php - if you want to do that, you must use option (1).
Php can't write files unless (a) the parent directory was created by php (and so has the owner/group which php runs under) or (b) the folder is CHMOD at 777 (which lets anything write there regardless of UID).
You don't want to leave a folder open on 777, so you can either:
(1) Use the php fn mkdir() to create writable folders with the php owner/group
(2) Or you can open it up the folder to 777 with your ftp program, write the file with php, and then CHMOD the folder back to 755. The file you just wrote has the php owner/group and so php can write to it again later even if the parent directory has a different owner group and is CHMOD 755. Of course, now you can't write NEW files there with php - if you want to do that, you must use option (1).
-
anything000
- Forum Newbie
- Posts: 11
- Joined: Sat Nov 29, 2003 10:39 am
Shell access? The site I'm working with is a subdomain which I have limited access to everything in that directory for my subdomain. But then I also have seperate ftp access to the server the domain is refering to.
Making a dir doesn't work everytime. After I make it once, I'll get errors if I try to remake it because it already exists.(I've tried so.)
I'm using FlashFXP and do not understand how to use this command and what to do after I've identified Own/Group files/folders.
Making a dir doesn't work everytime. After I make it once, I'll get errors if I try to remake it because it already exists.(I've tried so.)
I'm using FlashFXP and do not understand how to use this command and what to do after I've identified Own/Group files/folders.
-
d3ad1ysp0rk
- Forum Donator
- Posts: 1661
- Joined: Mon Oct 20, 2003 8:31 pm
- Location: Maine, USA