示例#1
0
 /**
  * Статический метод для получения MIME типа файла
  *
  * @param string $filePath
  * @return string
  */
 public static function mime($filePath)
 {
     if (empty(self::$_instance)) {
         self::$_instance = new self();
     }
     return self::$_instance->mimeType($filePath);
 }
 /**
  * Скачать архив с резервной копией
  *
  */
 public function downloadAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(TRUE);
     if ($this->hasParam('dir')) {
         $dir = $this->getParam('dir');
         $zip = new ZipArchive();
         $ret = $zip->open($zipFile = TEMP_PATH . DS . $dir . '.zip', ZipArchive::OVERWRITE);
         if ($ret !== TRUE) {
             printf('Failed with code %d', $ret);
         } else {
             $options = array('add_path' => 'backup/', 'remove_all_path' => TRUE);
             $zip->addGlob(TEMP_PATH . DS . 'Backups/' . $dir . '/*.*', GLOB_BRACE, $options);
             $zip->close();
             header('Content-Type: ' . System_Mime_Type::mime($zipFile));
             header('Content-Length: ' . filesize($zipFile));
             header("Content-Disposition: attachment; filename=\"" . basename($zipFile) . "\";");
             header("Content-Transfer-Encoding: binary");
             ob_end_flush();
             readfile($zipFile);
             unlink($zipFile);
             exit;
         }
     }
 }
示例#3
0
 /**
  * Получаем MIME файла
  *
  * @param string $filePath	Путь к файлу
  * @return string
  */
 public static function getMime($filePath)
 {
     return System_Mime_Type::mime($filePath);
 }