コード例 #1
0
ファイル: Tar.class.php プロジェクト: ZerGabriel/WCF
 /** 
  * @see	wcf\system\io\IArchive::extract()
  */
 public function extract($index, $destination)
 {
     if (!$this->read) {
         $this->open();
         $this->readContent();
     }
     $header = $this->getFileInfo($index);
     FileUtil::makePath(dirname($destination));
     if ($header['type'] === 'folder') {
         FileUtil::makePath($destination);
         return;
     }
     // seek to offset
     $this->file->seek($header['offset']);
     $targetFile = new File($destination);
     // read data
     $n = floor($header['size'] / 512);
     for ($i = 0; $i < $n; $i++) {
         $content = $this->file->read(512);
         $targetFile->write($content, 512);
     }
     if ($header['size'] % 512 != 0) {
         $content = $this->file->read(512);
         $targetFile->write($content, $header['size'] % 512);
     }
     $targetFile->close();
     if (FileUtil::isApacheModule() || !@$targetFile->is_writable()) {
         @$targetFile->chmod(0777);
     } else {
         @$targetFile->chmod(0755);
     }
     if ($header['mtime']) {
         @$targetFile->touch($header['mtime']);
     }
     // check filesize
     if (filesize($destination) != $header['size']) {
         throw new SystemException("Could not untar file '" . $header['filename'] . "' to '" . $destination . "'. Maybe disk quota exceeded in folder '" . dirname($destination) . "'.");
     }
     return true;
 }
コード例 #2
0
ファイル: Zip.class.php プロジェクト: ZerGabriel/WCF
 /**
  * @see wcf\system\io\IArchive::extract()
  */
 public function extract($offset, $destination)
 {
     if (!is_int($offset)) {
         $offset = $this->getIndexByFilename($offset);
     }
     try {
         $file = $this->readFile($offset);
     } catch (SystemException $e) {
         return false;
     }
     FileUtil::makePath(dirname($destination));
     if ($file['header']['type'] === 'folder') {
         FileUtil::makePath($destination);
         return;
     }
     $targetFile = new File($destination);
     $targetFile->write($file['content'], strlen($file['content']));
     $targetFile->close();
     if (FileUtil::isApacheModule() || !@$targetFile->is_writable()) {
         @$targetFile->chmod(0777);
     } else {
         @$targetFile->chmod(0755);
     }
     if ($file['header']['mtime']) {
         @$targetFile->touch($file['header']['mtime']);
     }
     // check filesize
     if (filesize($destination) != $file['header']['size']) {
         throw new SystemException("Could not unzip file '" . $file['header']['filename'] . "' to '" . $destination . "'. Maybe disk quota exceeded in folder '" . dirname($destination) . "'.");
     }
     return true;
 }