-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Description
Description
The following code:
php code
$zip = new ZipArchive();
$zip->open("c:/test.zip");
$zip->statName("a/b/c.txt");
$zip->statName("a//b//c.txt");
$zip->statName("/a/b/c.txt");
$zip->statName("//a/b/c.txt");
$zip->statName("\a\b\c.txt");
should output
array => name,crc,size
but output
$zip->statName("a/b/c.txt"); output false
$zip->statName("a//b//c.txt"); output false
$zip->statName("/a/b/c.txt"); output false
$zip->statName("//a/b/c.txt"); output false
$zip->statName("\a\b\c.txt"); output array => name,crc,size
solve immediate problems add function
public function Normalize($path, $remove_slashes_frist = false) {
$output = array();
$explode = explode("/", str_replace(array('/', '\'), "/", ($path)));
foreach ($explode as $value) {
if ($value == "..") {
array_pop($output);
} else if ($value !== ".") {
$output[] = ($value);
}
}
$strout = implode("/", $output);
while (strpos($strout, "//") !== false) {
$strout = str_replace("//", "/", $strout);
}
if ($remove_slashes_frist) {
$strout = ltrim($strout, "/");
}
return $strout;
}
PHP Version
php 7-8
Operating System
window 11