当前位置: 首页>>代码示例>>PHP>>正文


PHP File_Archive::_convertToWriter方法代码示例

本文整理汇总了PHP中File_Archive::_convertToWriter方法的典型用法代码示例。如果您正苦于以下问题:PHP File_Archive::_convertToWriter方法的具体用法?PHP File_Archive::_convertToWriter怎么用?PHP File_Archive::_convertToWriter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在File_Archive的用法示例。


在下文中一共展示了File_Archive::_convertToWriter方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: ExtractFiles

 /**
  * Extract archive Files
  *
  * @access  public
  * @param   array   $files        $_FILES array
  * @param   string  $dest         Destination directory(include end directory separator)
  * @param   bool    $extractToDir Create separate directory for extracted files
  * @param   bool    $overwrite    Overwrite directory if exist
  * @param   int     $max_size     Max size of file
  * @return  bool    Returns TRUE on success or FALSE on failure
  */
 static function ExtractFiles($files, $dest, $extractToDir = true, $overwrite = true, $max_size = null)
 {
     if (empty($files) || !is_array($files)) {
         return new Jaws_Error(_t('GLOBAL_ERROR_UPLOAD'), __FUNCTION__);
     }
     if (isset($files['name'])) {
         $files = array($files);
     }
     require_once PEAR_PATH . 'File/Archive.php';
     foreach ($files as $key => $file) {
         if (isset($file['error']) && !empty($file['error']) || !isset($file['name'])) {
             return new Jaws_Error(_t('GLOBAL_ERROR_UPLOAD_' . $file['error']), __FUNCTION__);
         }
         if (empty($file['tmp_name'])) {
             continue;
         }
         $ext = strrchr($file['name'], '.');
         $filename = substr($file['name'], 0, -strlen($ext));
         if (false !== stristr($filename, '.tar')) {
             $filename = substr($filename, 0, strrpos($filename, '.'));
             switch ($ext) {
                 case '.gz':
                     $ext = '.tgz';
                     break;
                 case '.bz2':
                 case '.bzip2':
                     $ext = '.tbz';
                     break;
                 default:
                     $ext = '.tar' . $ext;
             }
         }
         $ext = strtolower(substr($ext, 1));
         if (!File_Archive::isKnownExtension($ext)) {
             return new Jaws_Error(_t('GLOBAL_ERROR_UPLOAD_INVALID_FORMAT', $file['name']), __FUNCTION__);
         }
         if ($extractToDir) {
             $dest = $dest . $filename;
         }
         if ($extractToDir && !Jaws_Utils::mkdir($dest)) {
             return new Jaws_Error(_t('GLOBAL_ERROR_FAILED_CREATING_DIR', $dest), __FUNCTION__);
         }
         if (!Jaws_Utils::is_writable($dest)) {
             return new Jaws_Error(_t('GLOBAL_ERROR_FAILED_DIRECTORY_UNWRITABLE', $dest), __FUNCTION__);
         }
         $archive = File_Archive::readArchive($ext, $file['tmp_name']);
         if (PEAR::isError($archive)) {
             return new Jaws_Error($archive->getMessage(), __FUNCTION__);
         }
         $writer = File_Archive::_convertToWriter($dest);
         $result = $archive->extract($writer);
         if (PEAR::isError($result)) {
             return new Jaws_Error($result->getMessage(), __FUNCTION__);
         }
         //@unlink($file['tmp_name']);
     }
     return true;
 }
开发者ID:Dulciane,项目名称:jaws,代码行数:69,代码来源:Utils.php

示例2: extract

 /**
  * File_Archive::extract($source, $dest) is equivalent to $source->extract($dest)
  * If $source is a PEAR error, the error will be returned
  * It is thus easier to use this function than $source->extract, since it reduces the number of
  * error checking and doesn't force you to define a variable $source
  *
  * You may use strings as source and dest. In that case the source is automatically
  * converted to a reader using File_Archive::read and the dest is converted to a
  * writer using File_Archive::appender
  * Since PHP doesn't allow to pass literal strings by ref, you will have to use temporary
  * variables.
  * File_Archive::extract($src = 'archive.zip/', $dest = 'dir') will extract the archive to 'dir'
  * It is the same as
  * File_Archive::extract(
  *    File_Archive::read('archive.zip/'),
  *    File_Archive::appender('dir')
  * );
  * You may use any variable in the extract function ($from/$to, $a/$b...).
  *
  * @param File_Archive_Reader $source The source that will be read
  * @param File_Archive_Writer $dest Where to copy $source files
  * @param bool $autoClose if true (default), $dest will be closed after the extraction
  * @param int $bufferSize Size of the buffer to use to move data from the reader to the buffer
  *        If $bufferSize <= 0 (default), the blockSize option is used
  *        You shouldn't need to change that
  * @return null or a PEAR error if an error occured
  */
 function extract(&$sourceToConvert, &$destToConvert, $autoClose = true, $bufferSize = 0)
 {
     $source =& File_Archive::_convertToReader($sourceToConvert);
     if (PEAR::isError($source)) {
         return $source;
     }
     $dest =& File_Archive::_convertToWriter($destToConvert);
     return $source->extract($dest, $autoClose, $bufferSize);
 }
开发者ID:kosmosby,项目名称:medicine-prof,代码行数:36,代码来源:Archive.php


注:本文中的File_Archive::_convertToWriter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。