Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.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_Unzip - Fatal编程技术网

如何获取我刚刚解压缩的文件。PHP

如何获取我刚刚解压缩的文件。PHP,php,unzip,Php,Unzip,我正在解压一个文件,我不知道它的内容名称。我需要立即打开并处理此文件。我怎么能抓住它?不知道它的名字 这是我的密码 if($extension == 'ZIP' || $extension == 'zip'){ $zip = new ZipArchive; $res = $zip->open($_FILES['my_file']['tmp_name']); if ($res === TRUE) { $zip->extractTo

我正在解压一个文件,我不知道它的内容名称。我需要立即打开并处理此文件。我怎么能抓住它?不知道它的名字

这是我的密码

if($extension == 'ZIP' || $extension == 'zip'){
     $zip = new ZipArchive;
     $res = $zip->open($_FILES['my_file']['tmp_name']);
        if ($res === TRUE) {
          $zip->extractTo('../storage/unzipped/');
          $zip->close();

          // Get file, how? If I dont know the name, of the file inside the 
          // zip folder?


        } else {
            // Errors
        }
}

如果我知道文件名,我肯定知道如何打开文件……但在这种情况下,我不知道文件名,所以我需要以某种方式获取它。zip_entry_name()??

好吧,我在任何人回答之前就解决了这个问题……所以这是给任何需要它的人的

$entry = $zip->getNameIndex(0);
或者如果您的文件有多个文件夹/文件

$filenames=[];
for ($i = 0; $i < $zip->numFiles; $i++) {
   $filenames[] = $zip->getNameIndex($i);
};
if($extension == 'ZIP' || $extension == 'zip'){
 $zip = new ZipArchive;
 $res = $zip->open($_FILES['my_file']['tmp_name']);
    if ($res === TRUE) {
      $zip->extractTo('../storage/unzipped/');
      $filename = $zip->getNameIndex(0);
      // Open file or stream it or whatever you want
      // now that you have the name
      $zip->close();
    } else {
      // error
    } 
 }