comment mapper le chemin vers le fichier facilement?Comment mapper un chemin de fichier à partir d'un emplacement de dossier différent facilement?
public_html/api/function.php
<?php
function writetologfile($content)
{
$filename = 'logfile/testing_randomstring.txt';
if (!$handle = fopen($filename, 'a'))
{
echo "Cannot open file ($filename)";
exit;
}
fclose($handle);
}
?>
le chemin réel du fichier texte est en public_html/r/admin/logfile/testing_randomstring.txt
donc si je lance le script à public_html/folder1/folder2/addlog.php
, il ne sera pas en mesure de trouver le chemin du testing_randomstring.txt
addlog.php
<?php
include("../../api/function.php");
writetologfile('hahaha');
?>
Comment je peux facilement pointer vers ce chemin de fichier texte, peu importe d'où vient mon script d'appel php.
J'ai essayé de changer $ filename = 'logfile/testing_randomstring.txt'; à l'intérieur de la fonction writetologfile en appliquant au chemin fixe absolu, quelque chose comme $ filename = «/r/admin/logfile/testing_randomstring.txt », mais il ne fonctionne pas