Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 解压缩到目录-返回_Php_Zip - Fatal编程技术网

Php 解压缩到目录-返回

Php 解压缩到目录-返回,php,zip,Php,Zip,我正在将同一目录中的文件解压缩到一个名为“info”的文件夹中 这很好,它告诉我每个已经处理的文件 我遇到的问题是,当没有要提取的文件时,它会向我报告 这是我的代码: <?php $files = glob('*.{zip}', GLOB_BRACE); foreach($files as $file) { $zip = new ZipArchive; if ($zip->open($file) === TRUE) { $z

我正在将同一目录中的文件解压缩到一个名为“info”的文件夹中

这很好,它告诉我每个已经处理的文件

我遇到的问题是,当没有要提取的文件时,它会向我报告

这是我的代码:

    <?php

    $files = glob('*.{zip}', GLOB_BRACE);
    foreach($files as $file) {

    $zip = new ZipArchive;
    if ($zip->open($file) === TRUE) {
        $zip->extractTo('info');
        $zip->close();
        unlink($file);
        echo $file.' extracted sucessfully<br>';
       } else {
        echo 'failed';
    }
}
?>

当目录中没有要解压缩的.zip文件时,有人可以帮助显示消息吗

谢谢。


<?php

$files = glob('*.{zip}', GLOB_BRACE);
if (count($files) == 0) {
    echo 'No files to extract';
} else {

foreach($files as $file) {

$zip = new ZipArchive;
if ($zip->open($file) === TRUE) {
    $zip->extractTo('info');
    $zip->close();
    unlink($file);
    echo $file.' extracted sucessfully<br>';
   } else {
    echo 'failed';
}

}
}
?>

现在,只需在执行zip函数之前检查目录中的zip文件数量,就可以实现此功能。

难道您不能先查看目录中是否有文件吗?你能不能检查一下
如果(count($files)==0)
?这是个不错的主意,所以如果$zip->numFiles==0,那么就没有要提取的文件了。真的,我会尝试一下,报告返回工作状态,我会发布我的答案,以防其他人发现