Here is my code where I mention the file; the file is located in /var/www/wpscan/log.txt
and the PHP code runs in /var/www/html/form/index.php
where I write my logic.
When I run the file it displays the error "Unable to open file!".
$url = $_POST['url'];
$from_email = $_POST['email'];
$newdate=date('Y-m-d');
chdir('/var/www/wpscan/');
// current directory
$abc= getcwd();
$filepermission=$abc. '/log.txt';
$myfile = fopen( '/var/www/wpscan/log.txt', "w") or die("Unable to open file!");
$shelltest=shell_exec('ls');
fwrite($myfile, $shelltest);
fclose($myfile);
First:
sudo chmod 777 /var/www/wpscan/log.txt
Next:
$url = $_POST['url'];
$from_email = $_POST['email'];
$newdate=date('Y-m-d');
chdir('/var/www/wpscan/');
// current directory
$abc= getcwd();
$filepermission=$abc. '/log.txt';
$myfile = fopen($filepermission, "w") or die("Unable to open file!");
$shelltest=shell_exec('ls');
fwrite($myfile, $shelltest);
fclose($myfile);