Search code examples
phpunlink

unlink function not working for image in Internet Explorer


I have a problem in image unlink in Internet Explorer, but it works in Mozilla.

I have used php code:

<?php

unlink("./product_photos/".$name);


?>

Solution

  • PHP is not affected by browser quirks.

    If unlink() is failing, it probably has to do with your PHP. Does the file path point to a file? What does var_dump(file_exists("./product_photos/".$name)); say before deleting it? If it isn't (bool) true, there is your problem :)

    Be also sure that$name is sanitized if it is from the user, otherwise I may enter ../../../your-site/index.php (a directory traversal attack).