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


PHP JFactory::getStream方法代码示例

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


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

示例1: extractStream

 /**
  * Method to extract archive using stream objects
  *
  * @param   string  $archive      Path to Bzip2 archive to extract
  * @param   string  $destination  Path to extract archive to
  * @param   array   $options      Extraction options [unused]
  *
  * @return  boolean  True if successful
  */
 protected function extractStream($archive, $destination, $options = array())
 {
     // New style! streams!
     $input = JFactory::getStream();
     // Use bzip
     $input->set('processingmethod', 'bz');
     if (!$input->open($archive)) {
         throw new RuntimeException('Unable to read archive (bz2)');
     }
     $output = JFactory::getStream();
     if (!$output->open($destination, 'w')) {
         $input->close();
         throw new RuntimeException('Unable to write archive (bz2)');
     }
     do {
         $this->_data = $input->read($input->get('chunksize', 8196));
         if ($this->_data && !$output->write($this->_data)) {
             $input->close();
             throw new RuntimeException('Unable to write archive (bz2)');
         }
     } while ($this->_data);
     $output->close();
     $input->close();
     return true;
 }
开发者ID:Rai-Ka,项目名称:joomla-cms,代码行数:34,代码来源:bzip2.php

示例2: extract

 /**
  * Extract a ZIP compressed file to a given path
  *
  * @param	string	$archive		Path to ZIP archive to extract
  * @param	string	$destination	Path to extract archive into
  * @param	array	$options		Extraction options [unused]
  *
  * @return	boolean	True if successful
  * @since	1.5
  */
 public function extract($archive, $destination, $options = array())
 {
     // Initialise variables.
     $this->_data = null;
     $this->_metadata = null;
     $stream = JFactory::getStream();
     if (!$stream->open($archive, 'rb')) {
         $this->set('error.message', JText::_('JLIB_FILESYSTEM_TAR_UNABLE_TO_READ'));
         return JError::raiseWarning(100, $this->get('error.message'));
     }
     $position = 0;
     $return_array = array();
     $i = 0;
     $chunksize = 512;
     // tar has items in 512 byte packets
     while ($entry = $stream->read($chunksize)) {
         //$entry = &$this->_data[$i];
         $info = @unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/Ctypeflag/a100link/a6magic/a2version/a32uname/a32gname/a8devmajor/a8devminor", $entry);
         if (!$info) {
             $this->set('error.message', JText::_('JLIB_FILESYSTEM_TAR_UNABLE_TO_DECOMPRESS'));
             return JError::raiseWarning(100, $this->get('error.message'));
         }
         $size = octdec($info['size']);
         $bsize = ceil($size / $chunksize) * $chunksize;
         $contents = '';
         if ($size) {
             //$contents = fread($this->_fh, $size);
             $contents = substr($stream->read($bsize), 0, octdec($info['size']));
         }
         if ($info['filename']) {
             $file = array('attr' => null, 'data' => null, 'date' => octdec($info['mtime']), 'name' => trim($info['filename']), 'size' => octdec($info['size']), 'type' => isset($this->_types[$info['typeflag']]) ? $this->_types[$info['typeflag']] : null);
             if ($info['typeflag'] == 0 || $info['typeflag'] == 0x30 || $info['typeflag'] == 0x35) {
                 /* File or folder. */
                 $file['data'] = $contents;
                 $mode = hexdec(substr($info['mode'], 4, 3));
                 $file['attr'] = ($info['typeflag'] == 0x35 ? 'd' : '-') . ($mode & 0x400 ? 'r' : '-') . ($mode & 0x200 ? 'w' : '-') . ($mode & 0x100 ? 'x' : '-') . ($mode & 0x40 ? 'r' : '-') . ($mode & 0x20 ? 'w' : '-') . ($mode & 0x10 ? 'x' : '-') . ($mode & 0x4 ? 'r' : '-') . ($mode & 0x2 ? 'w' : '-') . ($mode & 0x1 ? 'x' : '-');
             } else {
                 /* Some other type. */
             }
             $type = strtolower($file['type']);
             if ($type == 'file' || $type == 'unix file') {
                 $path = JPath::clean($destination . DS . $file['name']);
                 // Make sure the destination folder exists
                 if (!JFolder::create(dirname($path))) {
                     $this->set('error.message', JText::_('JLIB_FILESYSTEM_TAR_UNABLE_TO_CREATE_DESTINATION'));
                     return JError::raiseWarning(100, $this->get('error.message'));
                 }
                 if (JFile::write($path, $contents, true) === false) {
                     $this->set('error.message', JText::_('JLIB_FILESYSTEM_TAR_UNABLE_TO_WRITE_ENTRY'));
                     return JError::raiseWarning(100, $this->get('error.message'));
                 }
                 $contents = '';
                 // reclaim some memory
             }
         }
     }
     $stream->close();
     return true;
 }
开发者ID:Joomla-on-NoSQL,项目名称:LaMojo,代码行数:69,代码来源:tar.php

示例3: extract

 /**
  * Extract a Gzip compressed file to a given path
  *
  * @access	public
  * @param	string	$archive		Path to ZIP archive to extract
  * @param	string	$destination	Path to extract archive to
  * @param	array	$options		Extraction options [unused]
  * @return	boolean	True if successful
  * @since	1.5
  */
 function extract($archive, $destination, $options = array())
 {
     // Initialise variables.
     $this->_data = null;
     if (!extension_loaded('zlib')) {
         $this->set('error.message', 'Zlib Not Supported');
         return JError::raiseWarning(100, $this->get('error.message'));
     }
     /*
     if (!$this->_data = JFile::read($archive)) {
     	$this->set('error.message', 'Unable to read archive');
     	return JError::raiseWarning(100, $this->get('error.message'));
     }
     
     $position = $this->_getFilePosition();
     $buffer = gzinflate(substr($this->_data, $position, strlen($this->_data) - $position));
     if (empty ($buffer)) {
     	$this->set('error.message', 'Unable to decompress data');
     	return JError::raiseWarning(100, $this->get('error.message'));
     }
     
     if (JFile::write($destination, $buffer) === false) {
     	$this->set('error.message', 'Unable to write archive');
     	return JError::raiseWarning(100, $this->get('error.message'));
     }
     return true;
     */
     // New style! streams!
     $input =& JFactory::getStream();
     $input->set('processingmethod', 'gz');
     // use gz
     if (!$input->open($archive)) {
         $this->set('error.message', 'Unable to read archive (gz)');
         return JError::raiseWarning(100, $this->get('error.message'));
     }
     $output =& JFactory::getStream();
     if (!$output->open($destination, 'w')) {
         $this->set('error.message', 'Unable to write archive (gz)');
         $input->close();
         // close the previous file
         return JError::raiseWarning(100, $this->get('error.message'));
     }
     $written = 0;
     do {
         $this->_data = $input->read($input->get('chunksize', 8196));
         if ($this->_data) {
             if (!$output->write($this->_data)) {
                 $this->set('error.message', 'Unable to write file (gz)');
                 return JError::raiseWarning(100, $this->get('error.message'));
             }
         }
     } while ($this->_data);
     $output->close();
     $input->close();
     return true;
 }
开发者ID:joebushi,项目名称:joomla,代码行数:66,代码来源:gzip.php

示例4: extract

 /**
  * Extract a Bzip2 compressed file to a given path
  *
  * @param   string   $archive		Path to Bzip2 archive to extract
  * @param   string   $destination	Path to extract archive to
  * @param   array    $options		Extraction options [unused]
  *
  * @return  boolean  True if successful
  * @since   11.1
  */
 public function extract($archive, $destination, $options = array())
 {
     // Initialise variables.
     $this->_data = null;
     if (!extension_loaded('bz2')) {
         $this->set('error.message', JText::_('JLIB_FILESYSTEM_BZIP_NOT_SUPPORTED'));
         return JError::raiseWarning(100, $this->get('error.message'));
     }
     if (!isset($options['use_streams']) || $options['use_streams'] == false) {
         // old style: read the whole file and then parse it
         if (!($this->_data = JFile::read($archive))) {
             $this->set('error.message', 'Unable to read archive');
             return JError::raiseWarning(100, $this->get('error.message'));
         }
         $buffer = bzdecompress($this->_data);
         unset($this->_data);
         if (empty($buffer)) {
             $this->set('error.message', 'Unable to decompress data');
             return JError::raiseWarning(100, $this->get('error.message'));
         }
         if (JFile::write($destination, $buffer) === false) {
             $this->set('error.message', 'Unable to write archive');
             return JError::raiseWarning(100, $this->get('error.message'));
         }
     } else {
         // New style! streams!
         $input = JFactory::getStream();
         $input->set('processingmethod', 'bz');
         // use bzip
         if (!$input->open($archive)) {
             $this->set('error.message', JText::_('JLIB_FILESYSTEM_BZIP_UNABLE_TO_READ'));
             return JError::raiseWarning(100, $this->get('error.message'));
         }
         $output = JFactory::getStream();
         if (!$output->open($destination, 'w')) {
             $this->set('error.message', JText::_('JLIB_FILESYSTEM_BZIP_UNABLE_TO_WRITE'));
             $input->close();
             // close the previous file
             return JError::raiseWarning(100, $this->get('error.message'));
         }
         $written = 0;
         do {
             $this->_data = $input->read($input->get('chunksize', 8196));
             if ($this->_data) {
                 if (!$output->write($this->_data)) {
                     $this->set('error.message', JText::_('JLIB_FILESYSTEM_BZIP_UNABLE_TO_WRITE_FILE'));
                     return JError::raiseWarning(100, $this->get('error.message'));
                 }
             }
         } while ($this->_data);
         $output->close();
         $input->close();
     }
     return true;
 }
开发者ID:ramdesh,项目名称:joomla-platform,代码行数:65,代码来源:bzip2.php

示例5: extract

 /**
  * Extract a Gzip compressed file to a given path
  *
  * @param   string  $archive      Path to ZIP archive to extract
  * @param   string  $destination  Path to extract archive to
  * @param   array   $options      Extraction options [unused]
  *
  * @return  boolean  True if successful
  *
  * @since   11.1
  */
 public function extract($archive, $destination, $options = array())
 {
     // Initialise variables.
     $this->_data = null;
     if (!extension_loaded('zlib')) {
         $this->set('error.message', JText::_('JLIB_FILESYSTEM_GZIP_NOT_SUPPORTED'));
         return JError::raiseWarning(100, $this->get('error.message'));
     }
     if (!isset($options['use_streams']) || $options['use_streams'] == false) {
         if (!($this->_data = JFile::read($archive))) {
             $this->set('error.message', 'Unable to read archive');
             return JError::raiseWarning(100, $this->get('error.message'));
         }
         $position = $this->_getFilePosition();
         $buffer = gzinflate(substr($this->_data, $position, strlen($this->_data) - $position));
         if (empty($buffer)) {
             $this->set('error.message', 'Unable to decompress data');
             return JError::raiseWarning(100, $this->get('error.message'));
         }
         if (JFile::write($destination, $buffer) === false) {
             $this->set('error.message', 'Unable to write archive');
             return JError::raiseWarning(100, $this->get('error.message'));
         }
     } else {
         // New style! streams!
         $input = JFactory::getStream();
         $input->set('processingmethod', 'gz');
         // use gz
         if (!$input->open($archive)) {
             $this->set('error.message', JText::_('JLIB_FILESYSTEM_GZIP_UNABLE_TO_READ'));
             return JError::raiseWarning(100, $this->get('error.message'));
         }
         $output = JFactory::getStream();
         if (!$output->open($destination, 'w')) {
             $this->set('error.message', JText::_('JLIB_FILESYSTEM_GZIP_UNABLE_TO_WRITE'));
             $input->close();
             // close the previous file
             return JError::raiseWarning(100, $this->get('error.message'));
         }
         do {
             $this->_data = $input->read($input->get('chunksize', 8196));
             if ($this->_data) {
                 if (!$output->write($this->_data)) {
                     $this->set('error.message', JText::_('JLIB_FILESYSTEM_GZIP_UNABLE_TO_WRITE_FILE'));
                     return JError::raiseWarning(100, $this->get('error.message'));
                 }
             }
         } while ($this->_data);
         $output->close();
         $input->close();
     }
     return true;
 }
开发者ID:NavaINT1876,项目名称:ccustoms,代码行数:64,代码来源:gzip.php

示例6: extract

 /**
  * Extract a Bzip2 compressed file to a given path
  *
  * @param   string  $archive      Path to Bzip2 archive to extract
  * @param   string  $destination  Path to extract archive to
  * @param   array   $options      Extraction options [unused]
  *
  * @return  boolean  True if successful
  *
  * @since   11.1
  * @throws  RuntimeException
  */
 public function extract($archive, $destination, array $options = array())
 {
     $this->_data = null;
     if (!extension_loaded('bz2')) {
         throw new RuntimeException('The bz2 extension is not available.');
     }
     if (!isset($options['use_streams']) || $options['use_streams'] == false) {
         // Old style: read the whole file and then parse it
         $this->_data = file_get_contents($archive);
         if (!$this->_data) {
             throw new RuntimeException('Unable to read archive');
         }
         $buffer = bzdecompress($this->_data);
         unset($this->_data);
         if (empty($buffer)) {
             throw new RuntimeException('Unable to decompress data');
         }
         if (JFile::write($destination, $buffer) === false) {
             throw new RuntimeException('Unable to write archive');
         }
     } else {
         // New style! streams!
         $input = JFactory::getStream();
         // Use bzip
         $input->set('processingmethod', 'bz');
         if (!$input->open($archive)) {
             throw new RuntimeException('Unable to read archive (bz2)');
         }
         $output = JFactory::getStream();
         if (!$output->open($destination, 'w')) {
             $input->close();
             throw new RuntimeException('Unable to write archive (bz2)');
         }
         do {
             $this->_data = $input->read($input->get('chunksize', 8196));
             if ($this->_data) {
                 if (!$output->write($this->_data)) {
                     $input->close();
                     throw new RuntimeException('Unable to write archive (bz2)');
                 }
             }
         } while ($this->_data);
         $output->close();
         $input->close();
     }
     return true;
 }
开发者ID:joomlatools,项目名称:joomla-platform,代码行数:59,代码来源:bzip2.php

示例7: extract

 /**
  * Extract a Gzip compressed file to a given path
  *
  * @param   string  $archive      Path to ZIP archive to extract
  * @param   string  $destination  Path to extract archive to
  * @param   array   $options      Extraction options [unused]
  *
  * @return  boolean  True if successful
  *
  * @since   11.1
  * @throws  RuntimeException
  */
 public function extract($archive, $destination, array $options = array())
 {
     $this->_data = null;
     if (!extension_loaded('zlib')) {
         throw new RuntimeException('The zlib extension is not available.');
     }
     if (!isset($options['use_streams']) || $options['use_streams'] == false) {
         $this->_data = file_get_contents($archive);
         if (!$this->_data) {
             throw new RuntimeException('Unable to read archive');
         }
         $position = $this->_getFilePosition();
         $buffer = gzinflate(substr($this->_data, $position, strlen($this->_data) - $position));
         if (empty($buffer)) {
             throw new RuntimeException('Unable to decompress data');
         }
         if (JFile::write($destination, $buffer) === false) {
             throw new RuntimeException('Unable to write archive');
         }
     } else {
         // New style! streams!
         $input = JFactory::getStream();
         // Use gz
         $input->set('processingmethod', 'gz');
         if (!$input->open($archive)) {
             throw new RuntimeException('Unable to read archive (gz)');
         }
         $output = JFactory::getStream();
         if (!$output->open($destination, 'w')) {
             $input->close();
             throw new RuntimeException('Unable to write archive (gz)');
         }
         do {
             $this->_data = $input->read($input->get('chunksize', 8196));
             if ($this->_data) {
                 if (!$output->write($this->_data)) {
                     $input->close();
                     throw new RuntimeException('Unable to write file (gz)');
                 }
             }
         } while ($this->_data);
         $output->close();
         $input->close();
     }
     return true;
 }
开发者ID:joomlatools,项目名称:joomla-platform,代码行数:58,代码来源:gzip.php

示例8: upload

 /**
  * Moves an uploaded file to a destination folder
  *
  * @param string $src The name of the php (temporary) uploaded file
  * @param string $dest The path (including filename) to move the uploaded file to
  *
  * @return boolean True on success
  * @since 1.5
  */
 public static function upload($src, $dest, $use_streams = false)
 {
     // Ensure that the path is valid and clean
     $dest = JPath::clean($dest);
     // Create the destination directory if it does not exist
     $baseDir = dirname($dest);
     if (!file_exists($baseDir)) {
         jimport('joomla.filesystem.folder');
         JFolder::create($baseDir);
     }
     if ($use_streams) {
         $stream = JFactory::getStream();
         if (!$stream->upload($src, $dest)) {
             JError::raiseWarning(21, JText::sprintf('JLIB_FILESYSTEM_ERROR_UPLOAD', $stream->getError()));
             return false;
         }
         return true;
     } else {
         // Initialise variables.
         jimport('joomla.client.helper');
         $FTPOptions = JClientHelper::getCredentials('ftp');
         $ret = false;
         if ($FTPOptions['enabled'] == 1) {
             // Connect the FTP client
             jimport('joomla.client.ftp');
             $ftp = JFTP::getInstance($FTPOptions['host'], $FTPOptions['port'], null, $FTPOptions['user'], $FTPOptions['pass']);
             //Translate path for the FTP account
             $dest = JPath::clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $dest), '/');
             // Copy the file to the destination directory
             if (is_uploaded_file($src) && $ftp->store($src, $dest)) {
                 unlink($src);
                 $ret = true;
             } else {
                 JError::raiseWarning(21, JText::_('JLIB_FILESYSTEM_ERROR_WARNFS_ERR02'));
             }
         } else {
             if (is_writeable($baseDir) && move_uploaded_file($src, $dest)) {
                 // Short circuit to prevent file permission errors
                 if (JPath::setPermissions($dest)) {
                     $ret = true;
                 } else {
                     JError::raiseWarning(21, JText::_('JLIB_FILESYSTEM_ERROR_WARNFS_ERR01'));
                 }
             } else {
                 JError::raiseWarning(21, JText::_('JLIB_FILESYSTEM_ERROR_WARNFS_ERR02'));
             }
         }
         return $ret;
     }
 }
开发者ID:akksi,项目名称:jcg,代码行数:59,代码来源:file.php

示例9: extract

 /**
  * Extract a Bzip2 compressed file to a given path
  *
  * @access	public
  * @param	string	$archive		Path to Bzip2 archive to extract
  * @param	string	$destination	Path to extract archive to
  * @param	array	$options		Extraction options [unused]
  * @return	boolean	True if successful
  * @since	1.5
  */
 function extract($archive, $destination, $options = array())
 {
     // Initialise variables.
     $this->_data = null;
     if (!extension_loaded('bz2')) {
         $this->set('error.message', 'BZip2 Not Supported');
         return JError::raiseWarning(100, $this->get('error.message'));
     }
     /* // old style: read the whole file and then parse it
     		if (!$this->_data = JFile::read($archive)) {
     			$this->set('error.message', 'Unable to read archive');
     			return JError::raiseWarning(100, $this->get('error.message'));
     		}
     
     		$buffer = bzdecompress($this->_data);
     		unset($this->_data);
     		if (empty ($buffer)) {
     			$this->set('error.message', 'Unable to decompress data');
     			return JError::raiseWarning(100, $this->get('error.message'));
     		}
     
     		if (JFile::write($destination, $buffer) === false) {
     			$this->set('error.message', 'Unable to write archive');
     			return JError::raiseWarning(100, $this->get('error.message'));
     		}
     		//*/
     // New style! streams!
     $input =& JFactory::getStream();
     $input->set('processingmethod', 'bz');
     // use bzip
     if (!$input->open($archive)) {
         $this->set('error.message', 'Unable to read archive (bz2)');
         return JError::raiseWarning(100, $this->get('error.message'));
     }
     $output =& JFactory::getStream();
     if (!$output->open($destination, 'w')) {
         $this->set('error.message', 'Unable to write archive (bz2)');
         $input->close();
         // close the previous file
         return JError::raiseWarning(100, $this->get('error.message'));
     }
     $written = 0;
     do {
         $this->_data = $input->read($input->get('chunksize', 8196));
         if ($this->_data) {
             if (!$output->write($this->_data)) {
                 $this->set('error.message', 'Unable to write file (bz2)');
                 return JError::raiseWarning(100, $this->get('error.message'));
             }
         }
     } while ($this->_data);
     $output->close();
     $input->close();
     return true;
 }
开发者ID:joebushi,项目名称:joomla,代码行数:65,代码来源:bzip2.php

示例10: realMultipleUpload

 public static function realMultipleUpload($frontEnd = 0)
 {
     $paramsC = JComponentHelper::getParams('com_phocagallery');
     $chunkMethod = $paramsC->get('multiple_upload_chunk', 0);
     $uploadMethod = $paramsC->get('multiple_upload_method', 1);
     JResponse::allowCache(false);
     // Chunk Files
     header('Content-type: text/plain; charset=UTF-8');
     header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
     header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
     header("Cache-Control: no-store, no-cache, must-revalidate");
     header("Cache-Control: post-check=0, pre-check=0", false);
     header("Pragma: no-cache");
     // Invalid Token
     JRequest::checkToken('request') or jexit(json_encode(array('jsonrpc' => '2.0', 'result' => 'error', 'code' => 100, 'message' => JText::_('COM_PHOCAGALLERY_ERROR') . ': ', 'details' => JText::_('COM_PHOCAGALLERY_INVALID_TOKEN'))));
     // Set FTP credentials, if given
     $ftp = JClientHelper::setCredentialsFromRequest('ftp');
     $path = PhocaGalleryPath::getPath();
     $file = JRequest::getVar('file', '', 'files', 'array');
     $chunk = JRequest::getVar('chunk', 0, '', 'int');
     $chunks = JRequest::getVar('chunks', 0, '', 'int');
     $folder = JRequest::getVar('folder', '', '', 'path');
     // Make the filename safe
     if (isset($file['name'])) {
         $file['name'] = JFile::makeSafe($file['name']);
     }
     if (isset($folder) && $folder != '') {
         $folder = $folder . DS;
     }
     $chunkEnabled = 0;
     // Chunk only if is enabled and only if flash is enabled
     if ($chunkMethod == 1 && $uploadMethod == 1 || $frontEnd == 0 && $chunkMethod == 0 && $uploadMethod == 1) {
         $chunkEnabled = 1;
     }
     if (isset($file['name'])) {
         // - - - - - - - - - -
         // Chunk Method
         // - - - - - - - - - -
         // $chunkMethod = 1, for frontend and backend
         // $chunkMethod = 0, only for backend
         if ($chunkEnabled == 1) {
             // If chunk files are used, we need to upload parts to temp directory
             // and then we can run e.g. the condition to recognize if the file already exists
             // We must upload the parts to temp, in other case we get everytime the info
             // that the file exists (because the part has the same name as the file)
             // so after first part is uploaded, in fact the file already exists
             // Example: NOT USING CHUNK
             // If we upload abc.jpg file to server and there is the same file
             // we compare it and can recognize, there is one, don't upload it again.
             // Example: USING CHUNK
             // If we upload abc.jpg file to server and there is the same file
             // the part of current file will overwrite the same file
             // and then (after all parts will be uploaded) we can make the condition to compare the file
             // and we recognize there is one - ok don't upload it BUT the file will be damaged by
             // parts uploaded by the new file - so this is why we are using temp file in Chunk method
             $stream = JFactory::getStream();
             // Chunk Files
             $tempFolder = 'pgpluploadtmpfolder' . DS;
             $filepathImgFinal = JPath::clean($path->image_abs . $folder . strtolower($file['name']));
             $filepathImgTemp = JPath::clean($path->image_abs . $folder . $tempFolder . strtolower($file['name']));
             $filepathFolderFinal = JPath::clean($path->image_abs . $folder);
             $filepathFolderTemp = JPath::clean($path->image_abs . $folder . $tempFolder);
             $maxFileAge = 60 * 60;
             // Temp file age in seconds
             $lastChunk = $chunk + 1;
             $realSize = 0;
             // Get the real size - if chunk is uploaded, it is only a part size, so we must compute all size
             // If there is last chunk we can computhe the whole size
             if ($lastChunk == $chunks) {
                 if (JFile::exists($filepathImgTemp) && JFile::exists($file['tmp_name'])) {
                     $realSize = filesize($filepathImgTemp) + filesize($file['tmp_name']);
                 }
             }
             // 5 minutes execution time
             @set_time_limit(5 * 60);
             // usleep(5000);
             // If the file already exists on the server:
             // - don't copy the temp file to final
             // - remove all parts in temp file
             // Because some parts are uploaded before we can run the condition
             // to recognize if the file already exists.
             if (JFile::exists($filepathImgFinal)) {
                 if ($lastChunk == $chunks) {
                     @JFolder::delete($filepathFolderTemp);
                 }
                 jexit(json_encode(array('jsonrpc' => '2.0', 'result' => 'error', 'code' => 108, 'message' => JText::_('COM_PHOCAGALLERY_ERROR') . ': ', 'details' => JText::_('COM_PHOCAGALLERY_FILE_ALREADY_EXISTS'))));
             }
             if (!PhocaGalleryFileUpload::canUpload($file, $errUploadMsg, $frontEnd, $chunkEnabled, $realSize)) {
                 // If there is some error, remove the temp folder with temp files
                 if ($lastChunk == $chunks) {
                     @JFolder::delete($filepathFolderTemp);
                 }
                 jexit(json_encode(array('jsonrpc' => '2.0', 'result' => 'error', 'code' => 104, 'message' => JText::_('COM_PHOCAGALLERY_ERROR') . ': ', 'details' => JText::_($errUploadMsg))));
             }
             // Ok create temp folder and add chunks
             if (!JFolder::exists($filepathFolderTemp)) {
                 @JFolder::create($filepathFolderTemp);
             }
             // Remove old temp files
             if (JFolder::exists($filepathFolderTemp)) {
//.........这里部分代码省略.........
开发者ID:scarsroga,项目名称:blog-soa,代码行数:101,代码来源:fileupload.php

示例11: move

 /**
  * Moves a folder.
  *
  * @param   string   $src          The path to the source folder.
  * @param   string   $dest         The path to the destination folder.
  * @param   string   $path         An optional base path to prefix to the file names.
  * @param   boolean  $use_streams  Optionally use streams.
  *
  * @return  mixed  Error message on false or boolean true on success.
  *
  * @since   11.1
  */
 public static function move($src, $dest, $path = '', $use_streams = false)
 {
     // Initialise variables.
     $FTPOptions = JClientHelper::getCredentials('ftp');
     if ($path) {
         $src = JPath::clean($path . '/' . $src);
         $dest = JPath::clean($path . '/' . $dest);
     }
     if (!self::exists($src)) {
         return JText::_('JLIB_FILESYSTEM_ERROR_FIND_SOURCE_FOLDER');
     }
     if (self::exists($dest)) {
         return JText::_('JLIB_FILESYSTEM_ERROR_FOLDER_EXISTS');
     }
     if ($use_streams) {
         $stream = JFactory::getStream();
         if (!$stream->move($src, $dest)) {
             return JText::sprintf('JLIB_FILESYSTEM_ERROR_FOLDER_RENAME', $stream->getError());
         }
         $ret = true;
     } else {
         if ($FTPOptions['enabled'] == 1) {
             // Connect the FTP client
             jimport('joomla.client.ftp');
             $ftp = JFTP::getInstance($FTPOptions['host'], $FTPOptions['port'], null, $FTPOptions['user'], $FTPOptions['pass']);
             //Translate path for the FTP account
             $src = JPath::clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $src), '/');
             $dest = JPath::clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $dest), '/');
             // Use FTP rename to simulate move
             if (!$ftp->rename($src, $dest)) {
                 return JText::_('Rename failed');
             }
             $ret = true;
         } else {
             if (!@rename($src, $dest)) {
                 return JText::_('Rename failed');
             }
             $ret = true;
         }
     }
     return $ret;
 }
开发者ID:Roma48,项目名称:abazherka_old,代码行数:54,代码来源:folder.php

示例12: upload

 /**
  * Moves an uploaded file to a destination folder
  *
  * @param   string   $src              The name of the php (temporary) uploaded file
  * @param   string   $dest             The path (including filename) to move the uploaded file to
  * @param   boolean  $use_streams      True to use streams
  * @param   boolean  $allow_unsafe     Allow the upload of unsafe files
  * @param   boolean  $safeFileOptions  Options to JFilterInput::isSafeFile
  *
  * @return  boolean  True on success
  *
  * @since   11.1
  */
 public static function upload($src, $dest, $use_streams = false, $allow_unsafe = false, $safeFileOptions = array())
 {
     if (!$allow_unsafe) {
         $descriptor = array('tmp_name' => $src, 'name' => basename($dest), 'type' => '', 'error' => '', 'size' => '');
         $isSafe = JFilterInput::isSafeFile($descriptor, $safeFileOptions);
         if (!$isSafe) {
             JLog::add(JText::sprintf('JLIB_FILESYSTEM_ERROR_WARNFS_ERR03', $dest), JLog::WARNING, 'jerror');
             return false;
         }
     }
     // Ensure that the path is valid and clean
     $pathObject = new JFilesystemWrapperPath();
     $dest = $pathObject->clean($dest);
     // Create the destination directory if it does not exist
     $baseDir = dirname($dest);
     if (!file_exists($baseDir)) {
         $folderObject = new JFilesystemWrapperFolder();
         $folderObject->create($baseDir);
     }
     if ($use_streams) {
         $stream = JFactory::getStream();
         if (!$stream->upload($src, $dest)) {
             JLog::add(JText::sprintf('JLIB_FILESYSTEM_ERROR_UPLOAD', $stream->getError()), JLog::WARNING, 'jerror');
             return false;
         }
         return true;
     } else {
         $FTPOptions = JClientHelper::getCredentials('ftp');
         $ret = false;
         if ($FTPOptions['enabled'] == 1) {
             // Connect the FTP client
             $ftp = JClientFtp::getInstance($FTPOptions['host'], $FTPOptions['port'], array(), $FTPOptions['user'], $FTPOptions['pass']);
             // Translate path for the FTP account
             $dest = $pathObject->clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $dest), '/');
             // Copy the file to the destination directory
             if (is_uploaded_file($src) && $ftp->store($src, $dest)) {
                 unlink($src);
                 $ret = true;
             } else {
                 JLog::add(JText::sprintf('JLIB_FILESYSTEM_ERROR_WARNFS_ERR04', $src, $dest), JLog::WARNING, 'jerror');
             }
         } else {
             if (is_writeable($baseDir) && move_uploaded_file($src, $dest)) {
                 // Short circuit to prevent file permission errors
                 if ($pathObject->setPermissions($dest)) {
                     $ret = true;
                 } else {
                     JLog::add(JText::_('JLIB_FILESYSTEM_ERROR_WARNFS_ERR01'), JLog::WARNING, 'jerror');
                 }
             } else {
                 JLog::add(JText::sprintf('JLIB_FILESYSTEM_ERROR_WARNFS_ERR04', $src, $dest), JLog::WARNING, 'jerror');
             }
         }
         return $ret;
     }
 }
开发者ID:adjaika,项目名称:J3Base,代码行数:69,代码来源:file.php

示例13: extractStream

 /**
  * Method to extract archive using stream objects
  *
  * @param   string  $archive      Path to ZIP archive to extract
  * @param   string  $destination  Path to extract archive to
  * @param   array   $options      Extraction options [unused]
  *
  * @return  boolean  True if successful
  */
 protected function extractStream($archive, $destination, $options = array())
 {
     // New style! streams!
     $input = JFactory::getStream();
     // Use gz
     $input->set('processingmethod', 'gz');
     if (!$input->open($archive)) {
         return $this->raiseWarning(100, 'Unable to read archive (gz)');
     }
     $output = JFactory::getStream();
     if (!$output->open($destination, 'w')) {
         $input->close();
         return $this->raiseWarning(100, 'Unable to write archive (gz)');
     }
     do {
         $this->_data = $input->read($input->get('chunksize', 8196));
         if ($this->_data && !$output->write($this->_data)) {
             $input->close();
             return $this->raiseWarning(100, 'Unable to write file (gz)');
         }
     } while ($this->_data);
     $output->close();
     $input->close();
     return true;
 }
开发者ID:ITPrism,项目名称:GamificationDistribution,代码行数:34,代码来源:gzip.php

示例14: copy

 /**
  * Copy a folder.
  *
  * @param   string   $src          The path to the source folder.
  * @param   string   $dest         The path to the destination folder.
  * @param   string   $path         An optional base path to prefix to the file names.
  * @param   boolean  $force        Force copy.
  * @param   boolean  $use_streams  Optionally force folder/file overwrites.
  *
  * @return  boolean  True on success.
  *
  * @since   11.1
  * @throws  RuntimeException
  */
 public static function copy($src, $dest, $path = '', $force = false, $use_streams = false)
 {
     @set_time_limit(ini_get('max_execution_time'));
     //if (Zend_Registry::isRegistered('logger')):
     //  $logger = Zend_Registry::get('logger');
     //endif;
     if ($path) {
         $src = JPath::clean($path . '/' . $src);
         $dest = JPath::clean($path . '/' . $dest);
     }
     // Eliminate trailing directory separators, if any
     $src = rtrim($src, DIRECTORY_SEPARATOR);
     $dest = rtrim($dest, DIRECTORY_SEPARATOR);
     if (!self::exists($src)) {
         throw new RuntimeException('Source folder not found', -1);
     }
     if (self::exists($dest) && !$force) {
         throw new RuntimeException('Destination folder not found', -1);
     }
     // Make sure the destination exists
     if (!self::create($dest)) {
         throw new RuntimeException('Cannot create destination folder', -1);
     }
     if (!($dh = @opendir($src))) {
         throw new RuntimeException('Cannot open source folder', -1);
     }
     // Walk through the directory copying files and recursing into folders.
     while (($file = readdir($dh)) !== false) {
         $sfid = $src . '/' . $file;
         $dfid = $dest . '/' . $file;
         switch (filetype($sfid)) {
             case 'dir':
                 if ($file != '.' && $file != '..') {
                     $ret = self::copy($sfid, $dfid, null, $force, $use_streams);
                     if ($ret !== true) {
                         return $ret;
                     }
                 }
                 break;
             case 'file':
                 if ($use_streams) {
                     $stream = JFactory::getStream();
                     if (!$stream->copy($sfid, $dfid)) {
                         throw new RuntimeException('Cannot copy file: ' . $stream->getError(), -1);
                     }
                 } else {
                     if (!@copy($sfid, $dfid)) {
                         throw new RuntimeException('Copy file failed', -1);
                     }
                 }
                 break;
         }
     }
     return true;
 }
开发者ID:visualweber,项目名称:appzf1,代码行数:69,代码来源:Folder.php

示例15: move

 /**
  * Moves a folder.
  *
  * @param string The path to the source folder.
  * @param string The path to the destination folder.
  * @param string An optional base path to prefix to the file names.
  * @return mixed Error message on false or boolean true on success.
  * @since 1.5
  */
 function move($src, $dest, $path = '', $use_streams = false)
 {
     // Initialise variables.
     jimport('joomla.client.helper');
     $FTPOptions = JClientHelper::getCredentials('ftp');
     if ($path) {
         $src = JPath::clean($path . DS . $src);
         $dest = JPath::clean($path . DS . $dest);
     }
     if (!JFolder::exists($src)) {
         return JText::_('Cannot find source folder');
     }
     if (JFolder::exists($dest)) {
         return JText::_('Folder already exists');
     }
     if ($use_streams) {
         $stream =& JFactory::getStream();
         if (!$stream->move($src, $dest)) {
             return JText::_('Rename failed') . ': ' . $stream->getError();
             //return JError::raiseError(-1, JText::_('Rename failed').': '. $stream->getError()));
         }
         $ret = true;
     } else {
         if ($FTPOptions['enabled'] == 1) {
             // Connect the FTP client
             jimport('joomla.client.ftp');
             $ftp =& JFTP::getInstance($FTPOptions['host'], $FTPOptions['port'], null, $FTPOptions['user'], $FTPOptions['pass']);
             //Translate path for the FTP account
             $src = JPath::clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $src), '/');
             $dest = JPath::clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $dest), '/');
             // Use FTP rename to simulate move
             if (!$ftp->rename($src, $dest)) {
                 return JText::_('Rename failed');
             }
             $ret = true;
         } else {
             if (!@rename($src, $dest)) {
                 return JText::_('Rename failed');
             }
             $ret = true;
         }
     }
     return $ret;
 }
开发者ID:joebushi,项目名称:joomla,代码行数:53,代码来源:folder.php


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