I have the below code (part of a function) that i run on my wordpress site. It works fine, but it also creates a system file (starting with a '.') for each file. This wouldn't normally be a problem but my HTML5 audio player picks these files up, and obviously can't play them so it looks like the player is broken.
Is there a way to stop the creation of these files from the Zip side of it? Or am i going to have to stop it from the player side?
I would rather stop them being created at all, as they take up space.
The code is:
// Unzip files to temp unzip folder, ignoring anything that is not a .mp3 extension
$zip = new ZipArchive();
$filename = $zip_file_path;
if ($zip->open($filename)!==TRUE) {
exit("cannot open <$filename>\n");
}
for ($i=0; $i<$zip->numFiles;$i++) {
$info = $zip->statIndex($i);
$file = pathinfo($info['name']);
if(strtolower($file['extension']) == "mp3") {
file_put_contents($temp_unzip_path.'/'.basename($info['name']), $zip->getFromIndex($i));
} else {
$zip->deleteIndex($i);
}
}
$zip->close();
为什么不通过检查文件名的第一个字符不是句号来增加mp3的条件呢?
if(strtolower($file['extension']) == "mp3" && $info['name'][0] != '.') {
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.