**已关闭。**此问题需要debugging details。目前不接受回答。
编辑问题以包括desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将帮助其他人回答问题。
17小时前关闭
Improve this question的
我试图创建一个文本文件,使用PHP程序,这是不是在Ubuntu的www目录,假设文件是/home/adminpc/index. php有另一个文件在www目录(/var/www/html/index.php),其中这个index.php文件有助于调用index.php文件
我在ubuntu18.0464位上用php5.6试过这个
我只安装了php,我没有在ubuntu中使用LAMP
index.php
<html>
<body>
<p>CLick on the Link</p><br/>
<a href="check.php" >Link</a> //Click on this link redirect to check.php
</body>
</html>
字符串
check.php
<?php include ('/home/adminpc/create.php'); ?> //This file is inside www directory
型
PHP
<?php
$structure = '/home/adminpc/Test';
if (!mkdir($structure, 0777, true)) {
die('Failed to create folders...');
}
//CREATE FILE
$name = "Test/test.txt";
$handle = fopen($name, "w");
fwrite($handle, "test,9944");
fclose($handle);
?>
型
我必须在localhost中运行index.php
应在**/home/adminpc中创建名为Test的目录,并在Test目录中创建名为test的文件,其中包含数据9944**或任何其他数据
2条答案
按热度按时间um6iljoc1#
第一个月
这里的文件路径是相对于执行文件(即
index.php
)的。使用__DIR__
可以获得create.php
中的相对路径$name = __DIR__ . "/Test/test.txt";
个vhmi4jdf2#
转到您的目录
运行
php -S localhost:8000
(或将8000替换为其他端口)如果文件名是索引,当你点击地址时它会自动运行,否则你必须指定文件名。