PHP文件解压,压缩文件遍历,文件夹遍历

来源:互联网 发布:英语四级软件推荐 编辑:程序博客网 时间:2024/04/30 06:00
//解压文件//$zip = new ZipArchive();$path = '../files/CustomPortrait/2.0.zip';$unzipPath = '../files/CustomPortrait/2.0';//if ($zip->open($path) === true) {//    $zip->extractTo($unzipPath);//}//$zip->close();////echo file_list($unzipPath);zip_test($path);function my_scandir($dir) {    $files = array();    if (is_dir($dir)) {        if ($handle = opendir($dir)) {            while (($file = readdir($handle)) !== false) {                if ($file != "." && $file != "..") {                    if (is_dir($dir . "/" . $file)) {                        $files[$file] = my_scandir($dir . "/" . $file);                    } else {                        $files[] = $dir . "/" . $file;                    }                }            }            closedir($handle);            return $files;        }    }}function file_list($path) {    if ($handle = opendir($path)) {        while (false !== ($file = readdir($handle))) {            if ($file != "." && $file != "..") {                if (is_dir($path . "/" . $file)) {                    echo $path . ": " . $file . "<br>";//去掉此行显示的是所有的非目录文件                    file_list($path . "/" . $file);                } else {                    echo $path . ": " . $file . "<br>";                }            }        }    }}function zip_test($path) {    $test = array();    $zip = new ZipArchive();    if ($zip->open($path) === TRUE) {        for ($i = 0; $i < $zip->numFiles; $i++) {            $contents = $zip->getNameIndex($i);            if(strpos($contents, '.png') !== false){                $test[$i] = $contents;            }        }    }   // print_r(array_values($test));    echo json_encode(array_values($test));   // echo json_encode($test);    $zip->close();}
0 0