$rootPath = "data/subset1/";
$fileName = $_GET["fn"];
$filePath = $rootPath.$fileName;
$myfile = fopen($filePath, "r") or die("Unable to open file!");
I am using the following line to encode the url
$link = 'http://'.$ip.'set/file.php?fn='.urlencode($line);
where $line = "textfile.txt"
.
I encoded the fn
part of the url using urlencode
. When I echo $filePath
, the path is exactly as it should be and fopen
succeeds when I manually type the output of echo $filePath
as the argument of fopen
, but fails, when using $filePath
as the argument.
file_exist()
displays a similar behaviour where the argument $filePath
results a FALSE
, but manually entering the path into file_exists()
results a TRUE
. I understand there is a systematic error of some sort but I am not sure what this error is. I have tried the alternatives such htmlentities but this doesn't encode spaces. urlencode seems to be the only one that takes care of all the special characters I throw at it. Does this have anything to do with charactersets? If so, I have tried using utf8_decode($line)
and that didn't change the results either.