Page 1 of 2
PHP file writing
Posted: Sat Nov 29, 2003 10:39 am
by anything000
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);
Posted: Sat Nov 29, 2003 10:50 am
by Weirdan
You have no permission to write to this file.
Posted: Sat Nov 29, 2003 10:58 am
by anything000
I have html and C++ experience. But I've just started with php. What would I have to do to receive permissions?
Posted: Sat Nov 29, 2003 11:04 am
by Weirdan
It isn't actually a PHP question. It's all about your OS.
If you do use some sort of *nix read the man chmod.
Posted: Sat Nov 29, 2003 11:57 am
by anything000
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);
Posted: Sat Nov 29, 2003 12:59 pm
by d3ad1ysp0rk
make sure you CHMOD the files to be writeable by your script.
Posted: Sat Nov 29, 2003 1:36 pm
by anything000
How would I go about doing that?
Posted: Sat Nov 29, 2003 2:01 pm
by m3mn0n
[php_man]chmod[/php_man]()
Posted: Sat Nov 29, 2003 3:31 pm
by anything000
After reading chmod()
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);
?>
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.
Posted: Sat Nov 29, 2003 3:38 pm
by Weirdan
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);
Posted: Sat Nov 29, 2003 4:00 pm
by mchaggis
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
Posted: Sat Nov 29, 2003 4:35 pm
by McGruff
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).
Posted: Sat Nov 29, 2003 5:36 pm
by anything000
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.
Posted: Sun Nov 30, 2003 11:37 am
by anything000
Anyone?
Posted: Sun Nov 30, 2003 12:42 pm
by d3ad1ysp0rk
are you using an FTP client?