使用php,如何从位于public_html文件夹内的文件编辑位于public_html文件夹外的文件夹中的文件?我尝试对public_html文件夹外的文件名使用include函数,但它运行的外部文件显示当前文件的内容(使用fputs),而不是仅更新外部文件。
<?php
include "hits.txt";
$filename = "hits.txt";
$count = file($filename);
$count[0]++;
$file = fopen ($filename, "w") or die ("Cannot find $filename");
fputs($file, "$count[0]");
fclose($file);
?>
据我所知,您想简单地编辑父目录中的文件吗?为此,您需要为open函数提供文件的绝对/相对路径。即:
$file_relative = "../../file.txt";
$file_absolute = "/some_file/www/file.txt";
fopen($file_relative, "w");
// Edit your file as necessary
请注意,虽然这在技术上是可行的,但可能是不允许的。您可能没有适当的权限编辑public_html以上的任何内容。