Mauro74
Mauro74

Reputation: 4826

php chmod usage

I'm trying to write a php file and set permission for it in order to be editable straight away after its creation.

Here's my code:

<?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);

chmod("tests/testFile.php", 0644);

?>

For some reason it's not working. The created file is still not editable unless I set manually the permissions. tests/ is the directory where the file has been created.

Any idea?

Upvotes: 2

Views: 3278

Answers (1)

Sam Becker
Sam Becker

Reputation: 19656

$myFile = "testFile.php";
$fh = fopen($myFile, 'w+') or die("can't open file");
chmod("tests/testFile.php", 0644);

The functions you are calling are referring to two different files. One in the directory of your PHP script and one in a directory called tests. Choose one, update your code and see if it works out for you.

Upvotes: 1

Related Questions