Delete a file in PHP using your .htaccess alias

0

I have a htaccess tag, it renames and gives hello name to the v.php file, leaving:

www.example.com/hola

So, I want to delete this " v.php ", by its name hello (written by htaccess)

$e = __DIR__ . "/hola";
$result = unlink($e);
if ($result){
    echo "done";
} else {
    echo "fail";
}

But give this error:

Warning: unlink(C:\xampp\x\xxx_xxx/hola): No such file or directory in C:\xampp\x\xxx_xxx\delete.php on line 3

But I need to remove it using this htccess rewrite, since I pull out the url from a database.

How can I do?

    
asked by Aspoky 09.07.2018 в 00:14
source

1 answer

0

I got the answer by my hand.

If I have an element in www.example.com/1.png and renamed as www.example.com/imagenes/1 , using a str_replace , it would be enough

$one = __DIR__ . "/imagenes/1"; // variable del Rewrite por htaccess
$two = str_replace("imagenes/1", "1.png", $one); // remplazando por el lugar original
unlink($two); // y se elimina.

And if you want to check if it was deleted:

$r = unlink($two); // das una variable para la comprobación
if ($r){
    echo "done"; // se eliminó
} else {
    echo "fail"; // hubó un error
}

This way you can delete the file, without revealing the actual location of the file to the user (in my case, I wanted this)

    
answered by 09.07.2018 в 01:55