I can not delete file with special chars using unlink().
My file name contains for example '," and nothing happen when I using unlink().
I tried to use addslashes and iconv, but it doesn't help..
Can anybody help me?
Filename for example: aaaż'.pdf
@Solution
$newFilename = str_replace('\\','',$filename);
$newFilename = iconv("UTF-8","Windows-1250",$newFilename);
unlink($newFilename);
$filename = 'my\,file\,name';
unlink($filename);
Try adding antislashes, it should work.
addslashes() function doesn't add antislashes to ",".
Use str_replace() to do that:
$filename = str_replace(',', '\,', $filename);
Can't reproduce that. Check the following example:
$filename = ",;\\'\"{}$!^#\n\t.txt";
touch($filename);
unlink($filename);
It works as expected.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.