Current location: Hot Scripts Forums » Programming Languages » PHP » Creating a 666 file?


Creating a 666 file?

Reply
  #1 (permalink)  
Old 02-03-04, 03:52 AM
tsb tsb is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Question Creating a 666 file?

Hi again.

I've written a script to edit an exsisting file (that is chmoded to 666) and everthing's fine, but what 'thing' (i can't remember the offical name) should i use if i want to view the file, and if it doesn't exsist, create it?

For example:

PHP Code:

<?php


$file 
"./file.php";
$fs fopen$file"r" ) or die("error when opening the file");

while (!
feof($fs)) {
   
$contents .= fgets($fs1024);
}

fclose($fs);

?>
<html>
<body>
<form action="save.php" method="post">
<input type=hidden name="file" value="<?php echo $file?>">
<textarea rows="10" cols="50" name="contents">
<?php echo htmlspecialchars($contents); ?>
</textarea>
</form>
</body>
</html>
That's what i have at the moment, with save.php being:

PHP Code:

<?php

$fs 
fopen$_POST["file"], "w" ) or die("error when opening the file info");
fwrite($fs$_POST["contents"]);
fclose($fs);
?>
That would edit file.php which is an already exsisting file that is chmoded to 666.

Now what would i use in place of r and w to view/write the file but if it doesn't exsist in either case, create it?

Also, is it possible for the file it creates to be automatically chmoded to 666 so i can edit it? That would be quite useful.

Thanks alot
Reply With Quote
  #2 (permalink)  
Old 02-03-04, 06:54 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
either using the 'a' (append) flag or 'w' (write) one , if the file wasn't found, PHP will attempt to create it..

and I don't think it's possible to write on a file or even read with 0666 mode! if I recall right this one makes the file forbbiden to view/right .. 0777 is the one that allows editing ...
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #3 (permalink)  
Old 02-03-04, 07:28 AM
tsb tsb is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
When i use append it doesn't read the files involved, is there one that will do all three? For me 666 works fine, so is it possible for the file it creates to be automatically chmoded to 666 so i can edit it? Thanks
Reply With Quote
  #4 (permalink)  
Old 02-04-04, 03:33 AM
tsb tsb is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
For example, with append it allows me to write and create but not read. With read it allows me to read and write but not create. I need something that will do all three really. Anyone?

Also, can, when i create the file, it be automatically chomded to 666?

Thanks
Reply With Quote
  #5 (permalink)  
Old 02-04-04, 03:46 AM
tsb tsb is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Nevermind, i've made it readable by just doing the command twice as follows:

PHP Code:

<?php 


$file 
"./file.php"
$fs fopen$file"a" ) or die("error when opening the file"); 
$fs fopen$file"r" ) or die("error when opening the file"); 

while (!
feof($fs)) { 
   
$contents .= fgets($fs1024); 


fclose($fs); 

?> 
<html> 
<body> 
<form action="save.php" method="post"> 
<input type=hidden name="file" value="<?php echo $file?>"> 
<textarea rows="10" cols="50" name="contents"> 
<?php echo htmlspecialchars($contents); ?> 
</textarea> 
</form> 
</body> 
</html>
It works, but would it in the long run? Also, i'm still confused over the matter involving the creation of a file automatically chmoded to 666.
Reply With Quote
  #6 (permalink)  
Old 02-04-04, 11:02 AM
lotrtrotk lotrtrotk is offline
New Member
 
Join Date: Feb 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Code:

// you can read AND write if you use 'a+' rather than 'a'

$fs fopen$file"a+" ) or die("error when opening the file"); 

Quote:
and I don't think it's possible to write on a file or even read with 0666 mode! if I recall right this one makes the file forbbiden to view/right .. 0777 is the one that allows editing ...
as I understand it....

1st number is owner's permissions
2nd is the group's permissions
3rd is everyone else's permissions

7 gives read, write & execute
6 gives read & write.... but no execute
Reply With Quote
  #7 (permalink)  
Old 02-04-04, 12:47 PM
tsb tsb is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
my server doesn't like a+ (don't ask why), but i got that working anyway...

i understand permissions, but i just want to know if it is possible for a form to chmod somethong to 666, or whatever persmission, when it creayes the file. thanks
Reply With Quote
  #8 (permalink)  
Old 02-04-04, 01:26 PM
tsb tsb is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
When i normally use...

PHP Code:

<?php

chmod
("file.php"0666);
?>
...in chmod.php, it comes up with...

Quote:
Warning: chmod() [function.chmod]: Operation not permitted in /users/web/blah/web/chmod.php on line 2
Any ideas why it does that, too?
Reply With Quote
  #9 (permalink)  
Old 02-08-04, 04:48 PM
tsb tsb is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Anyone know?
Reply With Quote
  #10 (permalink)  
Old 02-08-04, 05:35 PM
nfzgrld nfzgrld is offline
New Member
 
Join Date: Feb 2004
Location: Los Angeles CA
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by tsb
When i normally use...

PHP Code:

<?php

chmod
("file.php"0666);
?>
...in chmod.php, it comes up with...



Any ideas why it does that, too?
Remember two things, one, if it's a windows server, that ain't going to work anyway, but there's a real good change that's exactly the error you would get. The other thing to remember is that PHP access the file system on a *nix box as a user. If for some reason that user doesn't have appropriate permissions in the given directory you could get that. Although, PHP created the file, it doesn't take ownership, so this is very possible.

Nicholas Fitzgerald
http://www.axelis.com
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
write to beginning of file or reverse an array of binary data abtimoteo Perl 1 01-20-04 10:09 AM
creating a txt file :(((( z00m PHP 19 01-05-04 12:49 PM
Please I Need help before all my hair is gone! LisatheNovice Perl 6 11-22-03 03:05 PM
Upload file type and size limiter! Arctic ASP 1 08-02-03 07:06 PM
creating a install file darkcarnival PHP 8 07-01-03 07:06 AM


All times are GMT -5. The time now is 08:15 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.