コード例 #1
0
 /**
  * Extracts the current ZIP package.
  *
  * @param  string $file Full path to the ZIP package
  * @return bool True on success
  */
 protected function _unzip($file)
 {
     include_once Plugin::classPath('Installer') . 'Lib/pclzip.lib.php';
     $File = new File($file);
     $to = normalizePath($File->folder()->pwd() . '/' . $File->name() . '_unzip/');
     if (is_readable($to)) {
         $folder = new Folder($to);
         $folder->delete();
     } else {
         $folder = new Folder($to, true);
     }
     $PclZip = new \PclZip($file);
     $PclZip->delete(PCLZIP_OPT_BY_EREG, '/__MACOSX/');
     $PclZip->delete(PCLZIP_OPT_BY_EREG, '/\\.DS_Store$/');
     if ($PclZip->extract(PCLZIP_OPT_PATH, $to)) {
         list($directories, $files) = $folder->read(false, false, true);
         if (count($directories) === 1 && empty($files)) {
             $container = new Folder($directories[0]);
             $container->move(['to' => $to]);
         }
         $this->_workingDir = $to;
         return true;
     }
     $this->err(__d('installer', 'Unzip error: {0}', [$PclZip->errorInfo(true)]));
     return false;
 }
コード例 #2
0
ファイル: OrdersController.php プロジェクト: ranostaj/autocar
 /**
  * Copy Objednavku
  * @param $id
  */
 public function copy($id)
 {
     $row = $this->Orders->findById($id)->contain(["Accessories", "Images", "Files", "Statuses", "Operations"])->first();
     if (!$row) {
         throw new InternalErrorException("Chyba pri nacitani objednavky", 500);
     }
     try {
         $data = $row->toArray();
         // Copy All Images
         if ($data['images']) {
             foreach ($data['images'] as $key => $image) {
                 $file_name = new File($image['name']);
                 $new_file = md5($file_name->name() . time()) . "." . $file_name->ext();
                 if (copy('img/images/' . $file_name->name, 'img/images/' . $new_file)) {
                     $data['images'][$key]['name'] = $new_file;
                 }
             }
         }
         // Copy all Files
         if ($data['files']) {
             foreach ($data['files'] as $key => $file) {
                 $file_name = new File($file['name']);
                 $origin_file = preg_replace("/-copy-\\d{2}\\.\\d{2}\\.\\d{2}.\\d{2}.\\d{2}/", "", $file_name->name());
                 $new_file = $origin_file . "-copy-" . date("d.m.y-H-i") . "." . $file_name->ext();
                 if (copy('files/' . $file_name->name, 'files/' . $new_file)) {
                     $data['files'][$key]['name'] = $new_file;
                 }
             }
         }
         $order = $this->Orders->newEntity($data);
         $order->user_id = $this->getUserId();
         if (!$this->Orders->save($order)) {
             $message = ['message' => "error saving data", "data" => $order->errors()];
             throw new InternalErrorException(json_encode($message));
         }
     } catch (Exception $e) {
         throw new InternalErrorException($e->getMessage());
     }
     $this->set('row', $order);
     $this->set('_serialize', ['row']);
 }