Hello,
I have a problem with PHP, I need a script that deletes a file in a directory, all passed by URL, as in the script I made below:
<?php
$file = !isset($_GET["f"])?0:$_GET["f"];
$dir = !isset($_GET["dir"])?"":$_GET["dir"];
var_dump($dir.$file);
if ($file === 0)
{
echo 0;
die();
}
if (file_exists($dir.$file))
echo unlink($dir.$file);
else
echo 0;
? >
The problem is as follows, the function file_exists()
and unlink()
, of which I pass the path by parameter, say that the file I'm trying to access does not exist. Using var_dump()
I noticed that the return is as follows:
string(30)"C: \ xampp \ htdocs \ aaaa \ test.txt"
The file exists in the specified directory, but the functions say no. Look:
The file exists, the directory is correct, I have already tried it with \\ (use character deviation) but it is still in it. Please help me!
Addition of attempts already made:
- Switch file_exists () to is_file ()
- Use clearstatcache () before checking the file
- Switch \ to \\
No results, all failed.