如何从包含总目录路径的数组中创建递归 ZIP 文件,而内部没有 pdf 的名称



我有一个名为2019的目录。我想创建一个 ZIP 文件,其中包含文件夹 01-03 中的所有 pdf 文件。在 for 循环中,我用不为空的目录的所有路径填充数组。现在我不知道如何打开流或其他东西将数组值放入 for 循环中,并递归添加其中每个子文件夹路径下的所有 pdf。知道伙计们吗?

for ($i = 1; $i < 4; $i++) {
      // for the 3 months of this year
      $absolutepath = "$year_path/0$i";
      if (file_exists($absolutepath) && glob($absolutepath . "/*")) {
          // check if path/year/month exists
          // check if folder contains any files
          // store specific full paths inside array for use
          array_push($path_array, $absolutepath);
          }
} 
// how can i put here $path_array into a function to create zip file which contains all the pdfs under each subfolder path of the $path_array ???

看起来您创建字符串错误。您必须将路径分隔符的字符串外部的变量与前导零连接起来。我认为应该是:

$absolutepath = $year_path + "/0" + $i;

最新更新