如何更改目录路径并在Ubuntu上的PHP运行文件中创建一个空文件


How to change the directory path and create an empty file in PHP run file on Ubuntu

这是我提到文件的代码;文件位于/var/www/wpscan/log.txt中,PHP代码在/var/www/html/form/index.php中运行,我在这里编写逻辑。

当我运行该文件时,它会显示错误"无法打开文件!"。

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

第一个:

sudo chmod 777 /var/www/wpscan/log.txt

下一篇:

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