Example #1
0
 public function extractZipFile()
 {
     $this->file_name = html_entity_decode($this->file_name, ENT_QUOTES);
     $file_path = $this->intDir . DIRECTORY_SEPARATOR . $this->file_name;
     //The zip file name is set in $this->file_name
     $za = new ZipArchiveExtended();
     $za->open($file_path);
     try {
         $za->createTree();
         //get system temporary folder
         $tmpFolder = ini_get('upload_tmp_dir');
         empty($tmpFolder) ? $tmpFolder = "/tmp" : null;
         $tmpFolder .= "/" . uniqid('') . "/";
         mkdir($tmpFolder, 0777, true);
         $fileErrors = $za->extractFilesInTmp($tmpFolder);
         $za->close();
         //compose an array that has the same structure of $_FILES
         $filesArray = array();
         foreach ($za->treeList as $fileName) {
             $filesArray[$fileName] = array('name' => $fileName, 'tmp_name' => $tmpFolder . $fileName, 'error' => null, 'size' => filesize($tmpFolder . $fileName));
         }
         /***
          *
          * ERRORE di un file extratto dallo zip ( isset( $fileErrors[ $fileName ] ) ) ? $fileErrors[ $fileName ] :
          *
          **/
         // The $this->cookieDir parameter makes Upload get the upload directory from the cookie.
         // In this way it'll find the unzipped files
         $uploadFile = new Upload($this->cookieDir);
         $uploadFile->setRaiseException($this->stopOnFileException);
         try {
             $stdResult = $uploadFile->uploadFiles($filesArray);
             if ($this->uploadFailed($stdResult)) {
                 $this->uploadError = true;
                 $this->uploadedFiles = $stdResult;
             }
         } catch (Exception $e) {
             $stdResult = array();
             $this->result = array('errors' => array(array("code" => -1, "message" => $e->getMessage())));
             $this->api_output['message'] = $e->getMessage();
             return null;
         }
         return array_map("Upload::fixFileName", $za->treeList);
     } catch (Exception $e) {
         Log::doLog("ExtendedZipArchive Exception: {$e->getCode()} : {$e->getMessage()}");
         $this->result['errors'][] = array('code' => $e->getCode(), 'message' => "Zip error: " . $e->getMessage(), 'debug' => $this->file_name);
         return null;
     }
     return array();
 }