Example #1
0
 /**
  * @param boolean $echo
  * @return boolean
  */
 public function export($echo = true)
 {
     $z = new ZipArchive();
     $data = $this->getData();
     $filename = $this->getFilename();
     $path = pathinfo($filename, PATHINFO_FILENAME) . $this->_class->getExtension();
     $zip = sys_get_temp_dir() . '/' . uniqid() . '-' . $filename;
     $rv = $z->open($zip, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE);
     $rv = $z->addFromString($path, $data);
     $rv = $z->close();
     $zipdata = file_get_contents($zip);
     if ($echo) {
         $this->sendHeaders();
         echo $zipdata;
     }
     return $zipdata;
 }
Example #2
0
 /**
  * Upload and repack a file
  * 
  * @param string $input
  * @param object $uploader
  * @param string  $file_path
  * @param string $file_path_temp
  * return bool
  */
 public function uploadRepackFile($input, $uploader, $file_path, $file_path_temp)
 {
     //file is the filebrowse element name
     if (!$uploader->uploadFile($input)) {
         $this->setErrors($uploader->getMessage());
         return false;
     }
     //get uploaded file name, renames on upload//
     $file = $uploader->getUploadName();
     $file_name = strtok($file, '.');
     $file_extension = $uploader->getExtension($file);
     switch ($file_extension) {
         case 'gz':
             //unpackTarGz($path, $target)
             if (!$this->unpackTarGz($file_path . $file_name . '.tar.gz', $file_path_temp . $file_name)) {
                 $this->setErrors('Unable to unpack file "' . $file . '"');
                 return false;
             }
             //$this->setErrors('Unknown file extension in "' . $file . '"');
             //return $file_name . '.tar.gz';
             break;
         case 'zip':
             if (!$this->unpackZip($file_path . $file, $file_path_temp . $file_name)) {
                 $this->setErrors('Unable to unpack file "' . $file . '"');
                 return false;
             }
             break;
         default:
             $this->setErrors('Unknown file extension in "' . $file . '"');
             return false;
     }
     //do {
     /* if ($file_extension !== 'zip') {
        break;
        } */
     // Unpack zip file
     // Unlink uploaded Zip file
     unlink($file_path . $file);
     if (is_file($file_path . $file_name . '.tar.gz')) {
         unlink($file_path . $file_name . '.tar.gz');
     }
     // Create a tar.gz archive
     if (!$this->packTargz($file_path_temp . $file_name, $file_path . $file_name)) {
         $this->setErrors('Unable to create tar.gz from file "' . $file . '"');
         return false;
     }
     // Clean temp directory
     //Ut::cleanDirectory($file_path_temp . $file_name);
     $file = $file_name . '.tar.gz';
     //} while (false);
     return $file;
 }