-1

I have a directory with name 2019. I want to create a ZIP file which contains all the pdf files inside the folders 01-03. In a for loop, I fill an array with all the paths of the directories who are not empty. Now I don't know how to open a stream or something else to put the array values inside in a for loop and recursively add all pdfs under each subfolder path inside it. Any idea guys?

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 ???
Mayank Patel
  • 3,868
  • 10
  • 36
  • 59
Joe Mash
  • 39
  • 1
  • 6

1 Answers1

0

It looks like you are creating the string wrong. You have to concatenate the variables outside of the string for the path separator with the leading zero. I think it should be:

$absolutepath = $year_path + "/0" + $i;
thewhiteambit
  • 1,365
  • 16
  • 31