本文整理汇总了PHP中File_Archive::isKnownExtension方法的典型用法代码示例。如果您正苦于以下问题:PHP File_Archive::isKnownExtension方法的具体用法?PHP File_Archive::isKnownExtension怎么用?PHP File_Archive::isKnownExtension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类File_Archive
的用法示例。
在下文中一共展示了File_Archive::isKnownExtension方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: UnpackFiles
/**
* Check if input (an array of $_FILES) are .tar or .zip files, if they
* are then these get unpacked and returns an managed as $_FILES (returning
* an array with the same structure $_FILES uses and move pics to /tmp)
*
* @access public
* @param array $files $_FILES
* @return array $_FILES format
*/
function UnpackFiles($files)
{
if (!is_array($files)) {
return array();
}
$cleanFiles = array();
$tmpDir = sys_get_temp_dir();
$counter = 1;
require_once PEAR_PATH . 'File/Archive.php';
foreach ($files as $key => $file) {
if (empty($file['tmp_name'])) {
continue;
}
$ext = strrchr($file['name'], '.');
switch ($ext) {
case '.gz':
$ext = '.tgz';
break;
case '.bz2':
case '.bzip2':
$ext = '.tbz';
break;
}
$ext = strtolower(ltrim($ext, '.'));
if (File_Archive::isKnownExtension($ext)) {
$tmpArchiveName = $tmpDir . DIRECTORY_SEPARATOR . $file['name'];
if (!move_uploaded_file($file['tmp_name'], $tmpArchiveName)) {
continue;
}
$reader = File_Archive::read($tmpArchiveName);
$source = File_Archive::readArchive($ext, $reader);
if (!PEAR::isError($source)) {
while ($source->next()) {
$destFile = $tmpDir . DIRECTORY_SEPARATOR . basename($source->getFilename());
$sourceFile = $tmpArchiveName . '/' . $source->getFilename();
$extract = File_Archive::extract($sourceFile, $tmpDir);
if (PEAR::IsError($extract)) {
continue;
}
$cleanFiles['photo' . $counter] = array('name' => basename($source->getFilename()), 'type' => $source->getMime(), 'tmp_name' => $destFile, 'size' => @filesize($destFile), 'error' => 0);
$counter++;
}
}
} else {
$cleanFiles['photo' . $counter] = $file;
$counter++;
}
}
return $cleanFiles;
}
示例2: 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;
}
示例3: _readSource
//.........这里部分代码省略.........
if ((empty($URL) || is_dir($URL)) && $source === null) {
require_once dirname(__FILE__) . "/Archive/Reader/Directory.php";
require_once dirname(__FILE__) . "/Archive/Reader/ChangeName.php";
if ($uncompressionLevel != 0) {
require_once dirname(__FILE__) . "/Archive/Reader/Uncompress.php";
$result = new File_Archive_Reader_Uncompress(new File_Archive_Reader_Directory($std, '', $directoryDepth), $uncompressionLevel);
} else {
$result = new File_Archive_Reader_Directory($std, '', $directoryDepth);
}
if ($directoryDepth >= 0) {
require_once dirname(__FILE__) . '/Archive/Reader/Filter.php';
require_once dirname(__FILE__) . '/Archive/Predicate/MaxDepth.php';
$tmp =& File_Archive::filter(new File_Archive_Predicate_MaxDepth($directoryDepth), $result);
unset($result);
$result =& $tmp;
}
if (!empty($realSymbolic)) {
if ($symbolic === null) {
$realSymbolic = '';
}
$tmp =& new File_Archive_Reader_AddBaseName($realSymbolic, $result);
unset($result);
$result =& $tmp;
}
//If the URL can be interpreted as a file, and we are reading from the file system
} else {
if (is_file($URL) && substr($URL, -1) != '/' && $source === null) {
require_once dirname(__FILE__) . "/Archive/Reader/File.php";
$result = new File_Archive_Reader_File($URL, $realSymbolic);
//Else, we will have to build a complex reader
} else {
require_once dirname(__FILE__) . "/Archive/Reader/File.php";
$realPath = $std;
// Try to find a file with a known extension in the path (
// (to manage URLs like archive.tar/directory/file)
$pos = 0;
do {
if ($pos + 1 < strlen($realPath)) {
$pos = strpos($realPath, '/', $pos + 1);
} else {
$pos = false;
}
if ($pos === false) {
$pos = strlen($realPath);
}
$file = substr($realPath, 0, $pos);
$baseDir = substr($realPath, $pos + 1);
$dotPos = strrpos($file, '.');
$extension = '';
if ($dotPos !== false) {
$extension = substr($file, $dotPos + 1);
}
} while ($pos < strlen($realPath) && (!File_Archive::isKnownExtension($extension) || is_dir($file) && $source == null));
$reachable = $file;
//If we are reading from the file system
if ($source === null) {
//Create a file reader
$result = new File_Archive_Reader_File($file);
} else {
//Select in the source the file $file
require_once dirname(__FILE__) . "/Archive/Reader/Select.php";
$result = new File_Archive_Reader_Select($file, $source);
}
require_once dirname(__FILE__) . "/Archive/Reader/Uncompress.php";
$tmp = new File_Archive_Reader_Uncompress($result, $uncompressionLevel);
unset($result);
$result = $tmp;
//Select the requested folder in the uncompress reader
$isDir = $result->setBaseDir($std);
if (PEAR::isError($isDir)) {
return $isDir;
}
if ($isDir && $symbolic == null) {
//Default symbolic name for directories is empty
$realSymbolic = '';
}
if ($directoryDepth >= 0) {
//Limit the maximum depth if necessary
require_once dirname(__FILE__) . "/Archive/Predicate/MaxDepth.php";
$tmp = new File_Archive_Reader_Filter(new File_Archive_Predicate($directoryDepth + substr_count(substr($std, $pos + 1), '/')), $result);
unset($result);
$result =& $tmp;
}
if ($std != $realSymbolic) {
require_once dirname(__FILE__) . "/Archive/Reader/ChangeName.php";
//Change the base name to the symbolic one if necessary
$tmp = new File_Archive_Reader_ChangeBaseName($std, $realSymbolic, $result);
unset($result);
$result =& $tmp;
}
}
}
$cacheCondition = File_Archive::getOption('cacheCondition');
if ($cacheCondition !== false && preg_match($cacheCondition, $URL)) {
$tmp =& File_Archive::cache($result);
unset($result);
$result =& $tmp;
}
return $result;
}