Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从public_html文件夹内部编辑public_html文件夹外部的文件_Php - Fatal编程技术网

Php 从public_html文件夹内部编辑public_html文件夹外部的文件

Php 从public_html文件夹内部编辑public_html文件夹外部的文件,php,Php,使用php,如何从位于public_html文件夹内的文件编辑位于public_html文件夹外的文件夹中的文件?我尝试在public_html文件夹之外使用include函数作为文件名,但它运行外部文件,显示当前文件的内容(使用fputs),而不仅仅是更新外部文件 <?php include "hits.txt"; $filename = "hits.txt"; $count = file($filename); $count[0]++; $file = fopen ($fil

使用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

请注意,虽然这在技术上是可行的,但可能是不允许的。您可能没有适当的权限编辑公共html之上的任何内容。

我已将您的代码添加到原始问题中。仅供参考,下次您可以编辑您的问题而不是评论。人们喜欢看到格式化的代码。欢迎来到SO.:)非常感谢。下次我会包括代码。谢谢。这正是我想要的。