第二个Zip文件抛出无效或单元化的Zip对象

I am trying to unarchive a zip file that was inside another zip file to get to the xml file that is in the second zip file.

The big challenge with this file is that the files inside the zip file will always be different and therefore unknow. So I created a function to put the list of the archived archives into a text list. Then use this list to unarchive each file and extract the information that is needed from the xml file that is inside the second zip file.

Here is my code so far.

//Set the date
$day = date("mdY");
echo $day."<br>";

//URL to download file from for updating the prescription table
//$url = "ftp://public.nlm.nih.gov/nlmdata/.dailymed/dm_spl_daily_update_".$day.".zip";
  $url = "ftp://public.nlm.nih.gov/nlmdata/.dailymed/dm_spl_daily_update_09152016.zip";

//Saving the file on the server. 
 file_put_contents("Prescription_update.zip", fopen($url, 'r'));

//unzip the downloaded file
 $zip = new ZipArchive;

 if($zip->open('Prescription_update.zip')){
      $path = getcwd() . "/update/";
      $path = str_replace("\\","/",$path); 
     //echo $path;
      $zip->extractTo($path);
      $zip->close();
     print 'ok<br>';
  } else {
     print 'Failed';
}


// integer starts at 0 before counting
$i = 0; 
$dir = '/update/prescription/';
if ($handle = opendir($dir)) {
    while (($file = readdir($handle)) !== false){
        if (!in_array($file, array('.', '..')) && !is_dir($dir.$file)) 
            $i++;
    }
}
// prints out how many were in the directory need this for the loop later
   echo "There were $i files<br>";


 $dh  = opendir($dir);
 $files = array();
 while (false !== ($filename = readdir($dh))) {
     $files[] = $filename." 
";
 }
  //Created a list of files in the update/prescription folder
   file_put_contents("list.txt", $files);


 /*
  *  Creating a loop here to ready the names and extract the 
  *  XML file from the zipped files that are in the update/prescription folder
  *
  */

  $ii = 2;
  $fileName = new SplFileObject('list.txt');
  $fileName->seek($ii);
  echo $fileName."<br>";   //return the first file name from list.txt

  $zip = new ZipArchive;

  $zipObj = getcwd()."/update/prescription/".$fileName;
  $zipObj = str_replace("\\","/", $zipObj);
  echo $zipObj."<br>";
 if($zip->open($zipObj)){
       $path = getcwd() . "/update/prescription/tmp/";
       $path = str_replace("\\","/",$path); 
       mkdir($path);
       echo $path;
       $zip->extractTo($path);
       $zip->close();
       print 'ok<br>';
    } else {
       print 'Failed';
  }

Can't figure out why the second ZipArchive::extractTo: is throwing the error. I thought it may have been a path problem. I so I did the second string replacement hoping that would clear it up but it did not. So, throwing up my hands and asking for a second set of eyes on this one.

UPDATE ERROR LOG ENTRY

   [18-Sep-2016 02:24:24 America/Chicago] PHP   1. {main}() C:\emr-wamp\www\interface\weno\update_prescription_drug_table.php:0

   [18-Sep-2016 02:24:24 America/Chicago] PHP   2. ZipArchive->extractTo() C:\emr-wamp\www\interface\weno\update_prescription_drug_table.php:76

   [18-Sep-2016 02:24:24 America/Chicago] PHP Warning:  ZipArchive::close(): Invalid or unitialized Zip object in C:\emr-wamp\www\interface\weno\update_prescription_drug_table.php on line 77

 [18-Sep-2016 02:24:24 America/Chicago] PHP Stack trace:

 [18-Sep-2016 02:24:24 America/Chicago] PHP   1. {main}() C:\emr-wamp\www\interface\weno\update_prescription_drug_table.php:0

 [18-Sep-2016 02:24:24 America/Chicago] PHP   2. ZipArchive->close() C:\emr-wamp\www\interface\weno\update_prescription_drug_table.php:77

I was going to vote to delete this question but I thought it would be better to leave it over the long run.

The answer is

How to get PHP ZipArchive to work with variable

It seems that the whole name cannot be subbed as a variable. But if you sub part of the name it is allowed.

 $zipObj = getcwd()."/update/prescription/".$fileName;

It has to be subbed like

 $z->open("update/".$r.".zip"){
    //do something here
 }