Search code examples
phpunlink

php unlink() non-ascii characters = file not found


To be brief;

php unlink is working with files if their name is asci. However unlink produce file not found error if i try to delete a file with a name including ç ö etc.

Is there any way that i can fix this? Or is it a problem caused by the relation between PHP & Operating System.


Solution

  • It is definitive an encoding problem.

    Try this (if './çö' isn't UTF-8, dynamicly loaded for example):

    unlink(mb_convert_encoding('./çö', 'UTF-8'))
    

    Maybe you are using Windows? From here:

    unlink(iconv('utf-8', 'cp1252', './çö'));
    

    Anyway: You should avoid those filenames. If it comes from user: NEVER TRUST USER INPUT!