Issue
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?
Solution
$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.
Answered By - Sam152 Answer Checked By - Dawn Plyler (WPSolving Volunteer)