gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 12:59:18 26 4
gpt4 key购买 nike

这是我提到文件的代码;该文件位于 /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);

关于php - 如何更改目录路径并在 Ubuntu 上的 PHP 运行文件中创建一个空文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34685912/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com