예제 #1
0
파일: Unzip.php 프로젝트: bjtenao/tudu-web
 /**
  * 获取对象实例
  *
  * @return Tudu_Install_Function
  */
 public static function getInstance()
 {
     if (null === self::$_instance) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
예제 #2
0
 /**
  * 解压文件
  *
  * @param string $file
  * @return array
  */
 public function unZip($file)
 {
     if (!is_file($file)) {
         return array('success' => false, 'error' => 9, 'errormsg' => 'update zip file exists', 'file' => $file);
     }
     require_once 'Oray/Unzip.php';
     /* @var $unzip Oray_Unzip */
     $unzip = Oray_Unzip::getInstance();
     $zip = $unzip->readFile($file);
     $return = array('success' => true);
     foreach ($zip as $item) {
         if ($item->error != 0) {
             $return = array('success' => false, 'error' => $item->error, 'errormsg' => $item->errormsg, 'file' => $item->path . '/' . $item->name);
             break;
         }
         $dir = $this->_updatePath . DIRECTORY_SEPARATOR . $item->path;
         if (!$this->mkdirs($dir)) {
             $return = array('success' => false, 'error' => 10, 'errormsg' => 'mkdir failed', 'path' => $item->path);
             break;
         }
         $fp = @fopen($dir . DIRECTORY_SEPARATOR . $item->name, 'wb');
         if (!$fp) {
             $return = array('success' => false, 'error' => 8, 'errormsg' => 'fopen file failed', 'file' => $dir . '/' . $item->name);
             break;
         }
         @fwrite($fp, $item->data);
         @fclose($fp);
     }
     $return['count'] = $unzip->count();
     return $return;
 }