PDA

View Full Version : Creating Files and Changing permissions


Jasonb61
08-29-2002, 09:45 PM
Is it possible, in PHP, to make a *.txt file in a folder and then change the permissions of that file to 777?

Thanks,
JohnnyX

Spookster
08-29-2002, 10:16 PM
Yes

http://www.php.net/manual/en/function.chmod.php

Creating the file is easy:



<?php
$file_name = "filename.txt";
$data = "This will be the stuff you put into the file"."\n";

$file_pointer = fopen($file_name, "a");
$lock = flock($file_pointer, LOCK_EX);

if ($lock){
fputs($file_pointer, $data);
flock($file_pointer, LOCK_UN);
}

fclose($file_pointer);
?>