Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create a readable/writeable file.

Status
Not open for further replies.

Whispers

Technical User
Mar 20, 2002
2
US
I am having a hard time making my scripts accessible to my clientele. One problem is that they do not have experience with chmod settings. I, myself, have not used chmod with PHP with success. Instead of having my clients use WS_FTP (or some other program) I'd like my php to automatically chmod certain files.

IE

1. Try to read a file.
2. If you can't read from file...
see if the file exists.
3. If the file exists...
change the chmod to 0666.
4. If the file doesn't exist...
create file file.tw and chmod to 0666.

Could someone simply me with some source code that would accomplish this feat?

Tony Whispers
tonywhispers@hotmail.com
 
I dunno what OS your are using, but the following should work (untested though):
Code:
$filename =
Code:
"file.tw"
Code:
;
if(!file_exists($filename))
 {
Code:
  // create the file - it isn't there
Code:
  $file_handle = @fwrite(@fopen($filename,"w"), " ");
 }
Code:
// chmod the file now that it definitly exists
Code:
@chmod($filename, 0666);

$file_handle = @fopen($filename, "r");
Code:
//read the file into $contents
Code:
$contents = @fread($file_handle, @filesize($filename));
-gerrygerry
Go To
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top