Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php write file and set permission

I'm trying to create a php file which I can edit straight away without manually set the permissions.

I'm trying this...

<?php

$var = '<?php $mycontent = new Content(); echo $mycontent->block($p_name);?>';

$myFile = "testFile.php";

$fh = fopen($myFile, 'w+') or die("can't open file");

$stringData = $var;

fwrite($fh, $stringData);

fclose($fh);

?>

...it creates the file, but when I try to edit the file in my IDE it won't let me of course. I have to manually set the permission of the file created. Is there any way I can create the file and have the permission already set?

Thanks in advance

Mauro

like image 266
Mauro74 Avatar asked Nov 29 '22 04:11

Mauro74


1 Answers

Yes, you can thanks to PHP CHMOD

// Read and write for owner, read for everybody else
chmod("/somedir/somefile", 0644);
like image 90
Shikiryu Avatar answered Dec 06 '22 04:12

Shikiryu