Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete files with special characters in filenames

I need to delete old files with special characters in filenames like space,,,(,),! and so on via PHP. Classic unlink($filename) does not work for these files. How can I transform filenames to filenames which accepts unlink function and filesystem? It's running on a Solaris machine and I don't have another access to it.

like image 601
gadelat Avatar asked Nov 28 '25 00:11

gadelat


1 Answers

How are you constructing the $filename? unlink should work on any filename with special characters if you do the normal escaping on it. e.g.

for a file with a name of this has, various/wonky !characters in it, then

 $filename = 'this has\, various\/wonky \!characters in it';
 unlink($filename);

should work.

like image 72
Marc B Avatar answered Nov 29 '25 14:11

Marc B



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!