I have a zip file (A.zip) having multiple files in it. When I am trying to insert the filenames in my database field, it is getting inserted as blank in one of the fields.
Here is the code I am using:-
$filename = "A.zip";
$zip = zip_open($filename);
if ($zip) {
while ($zip_entry = zip_read($zip)) {
$zip_file_name = zip_entry_name($zip_entry);
$zip_file_name = preg_replace("/([!?:%,\[\]@{+;}=*<>~#\"^&*|()\\/])/", " ",$zip_file_name);
// Every single time, the file name is read, it is inserted in the database
}
zip_close($zip);
}
filenames in zip file:- 1) 178_!£$%^&&@{~~.xslx 2) 128_!£$%^@{~.xslx
I am replacing all the required special characters with the space (" "), but need to keep dollar ($) and pound (£) in the filename (when inserted).
Now, what is happening, all the required characters are correctly getting replaced with spaces and $ is also correctly placed, but when it comes to pound sign (£), it is getting replaced with a black diamond question mark (when I did console log) and a blank filename is getting inserted in the database.
When single file is inserted in the database, it is getting correctly inserted with the $ and pound(£) sign.
field name in the database is varchar(255) with utf8_general_ci as collation.
Also, the meta tag is set as charset UTF-8: -
I have tried looking out for solutions over the internet, but couldn't able to find the one related with zip file.
Just to note: All filenames with simple english characters and numbers are correctly getting inserted into the database.
Also, when I remove the pound sign (£), filename is correctly inserted..
Please..Any help is appreciated!!