如何在shell中创建文件exec命令php在ubuntu中返回错误(无法打开文件)



我想用PHP中的命令shell_exec创建一个空文件,并使用touch命令创建一个文件并打开它,但该文件没有创建,也无法写入该文件。

$newdate=date('Y-m-d');
echo $filepermission=__DIR__ . '/wp-scan'.$newdate.'.txt';
$filecreate='touch '.$filepermission;
$permissionfile='chmod -R 777 '.$filepermission;
shell_exec($filecreate);
$myfile = fopen(__DIR__ . '/wp-scan'.$newdate.'.txt', "w") or die("Unable to open file!");

您可以使用PHP函数来实现,不需要使用shell_exec

$newdate = date('Y-m-d');
$filename = __DIR__ . '/wp-scan'.$newdate.'.txt';
file_put_contents($filename, "") or die("Unable to create file!");
fchmod($filename, 0777) or die("Unable to change permissions!");
$myfile = fopen($filename, "w") or die("Unable to open file!");

最新更新