Using php, how can I edit a file that is located in a folder outside of the public_html folder from a file that is located inside the public_html folder? I tried using the include function for the filename of the file outside of the public_html folder, but it runs the external file displaying contents of it (using fputs) for the current file instead of just updating the external file.
<?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);
?>
From what I understand, you want to simply edit a file in the parent directory? To do this, you’ll need to provide the open function with either an absolute/relative path to your file. That is:
Please note, that while this is technically feasible, it may be disallowed. You may not have the appropriate permissions to edit anything above public_html.