本文整理汇总了PHP中file::getExtension方法的典型用法代码示例。如果您正苦于以下问题:PHP file::getExtension方法的具体用法?PHP file::getExtension怎么用?PHP file::getExtension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类file
的用法示例。
在下文中一共展示了file::getExtension方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getFiles
protected function getFiles($dir)
{
$thumbDir = "{$this->config['uploadDir']}/{$this->config['thumbsDir']}/{$dir}";
$dir = "{$this->config['uploadDir']}/{$dir}";
$return = array();
$files = dir::content($dir, array('types' => "file"));
if ($files === false) {
return $return;
}
foreach ($files as $file) {
$size = @getimagesize($file);
if (is_array($size) && count($size)) {
$thumb_file = "{$thumbDir}/" . basename($file);
if (!is_file($thumb_file)) {
$this->makeThumb($file, false);
}
$smallThumb = $size[0] <= $this->config['thumbWidth'] && $size[1] <= $this->config['thumbHeight'] && in_array($size[2], array(IMAGETYPE_GIF, IMAGETYPE_PNG, IMAGETYPE_JPEG));
} else {
$smallThumb = false;
}
$stat = stat($file);
if ($stat === false) {
continue;
}
$name = basename($file);
$ext = file::getExtension($file);
$bigIcon = file_exists("themes/{$this->config['theme']}/img/files/big/{$ext}.png");
$smallIcon = file_exists("themes/{$this->config['theme']}/img/files/small/{$ext}.png");
$thumb = file_exists("{$thumbDir}/{$name}");
$return[] = array('name' => stripcslashes($name), 'size' => $stat['size'], 'mtime' => $stat['mtime'], 'date' => @strftime($this->dateTimeSmall, $stat['mtime']), 'readable' => is_readable($file), 'writable' => file::isWritable($file), 'bigIcon' => $bigIcon, 'smallIcon' => $smallIcon, 'thumb' => $thumb, 'smallThumb' => $smallThumb);
}
return $return;
}
示例2: checkUploadedFile
protected function checkUploadedFile(array $aFile = null)
{
$config =& $this->config;
$file = $aFile === null ? $this->file : $aFile;
if (!is_array($file) || !isset($file['name'])) {
return $this->label("Unknown error");
}
if (is_array($file['name'])) {
foreach ($file['name'] as $i => $name) {
$return = $this->checkUploadedFile(array('name' => $name, 'tmp_name' => $file['tmp_name'][$i], 'error' => $file['error'][$i]));
if ($return !== true) {
return "{$name}: {$return}";
}
}
return true;
}
$extension = file::getExtension($file['name']);
$typePatt = strtolower(text::clearWhitespaces($this->types[$this->type]));
// CHECK FOR UPLOAD ERRORS
if ($file['error']) {
return $file['error'] == UPLOAD_ERR_INI_SIZE ? $this->label("The uploaded file exceeds {size} bytes.", array('size' => ini_get('upload_max_filesize'))) : ($file['error'] == UPLOAD_ERR_FORM_SIZE ? $this->label("The uploaded file exceeds {size} bytes.", array('size' => $_GET['MAX_FILE_SIZE'])) : ($file['error'] == UPLOAD_ERR_PARTIAL ? $this->label("The uploaded file was only partially uploaded.") : ($file['error'] == UPLOAD_ERR_NO_FILE ? $this->label("No file was uploaded.") : ($file['error'] == UPLOAD_ERR_NO_TMP_DIR ? $this->label("Missing a temporary folder.") : ($file['error'] == UPLOAD_ERR_CANT_WRITE ? $this->label("Failed to write file.") : $this->label("Unknown error."))))));
} elseif (substr($file['name'], 0, 1) == ".") {
return $this->label("File name shouldn't begins with '.'");
} elseif (substr($file['name'], -1) == "." || !$this->validateExtension($extension, $this->type)) {
return $this->label("Denied file extension.");
} elseif (preg_match('/^\\*([^ ]+)(.*)?$/s', $typePatt, $patt)) {
list($typePatt, $type, $params) = $patt;
$class = __NAMESPACE__ . "\\type_{$type}";
if (class_exists($class)) {
$type = new $class();
$cfg = $config;
$cfg['filename'] = $file['name'];
if (strlen($params)) {
$cfg['params'] = trim($params);
}
$response = $type->checkFile($file['tmp_name'], $cfg);
if ($response !== true) {
return $this->label($response);
}
} else {
return $this->label("Non-existing directory type.");
}
}
// IMAGE RESIZE
$img = image::factory($this->imageDriver, $file['tmp_name']);
if (!$img->initError && !$this->imageResize($img, $file['tmp_name'])) {
return $this->label("The image is too big and/or cannot be resized.");
}
return true;
}
示例3: getFiles
protected function getFiles($dir)
{
$thumbDir = "{$this->config['uploadDir']}/{$this->config['thumbsDir']}/{$dir}";
$dir = "{$this->config['uploadDir']}/{$dir}";
$return = array();
$files = dir::content($dir, array('types' => "file"));
if ($files === false) {
return $return;
}
foreach ($files as $file) {
$this->makeThumb($file, false);
$image = new gd($file);
$image = !$image->init_error && $image->get_width() <= $this->config['thumbWidth'] && $image->get_height() <= $this->config['thumbHeight'];
$stat = stat($file);
if ($stat === false) {
continue;
}
$name = basename($file);
$ext = file::getExtension($file);
$bigIcon = file_exists("themes/{$this->config['theme']}/img/files/big/{$ext}.png");
$smallIcon = file_exists("themes/{$this->config['theme']}/img/files/small/{$ext}.png");
$thumb = file_exists("{$thumbDir}/{$name}");
$return[] = array('name' => stripcslashes($name), 'size' => $stat['size'], 'mtime' => $stat['mtime'], 'date' => @strftime($this->dateTimeSmall, $stat['mtime']), 'readable' => is_readable($file), 'writable' => file::isWritable($file), 'bigIcon' => $bigIcon, 'smallIcon' => $smallIcon, 'thumb' => $thumb, 'smallThumb' => $image);
}
return $return;
}
示例4: act_mv_cbd
protected function act_mv_cbd()
{
$dir = $this->postDir();
if (!$this->config['access']['files']['move'] || !isset($_POST['dir']) || !is_dir($dir) || !is_readable($dir) || !dir::isWritable($dir) || !isset($_POST['files']) || !is_array($_POST['files']) || !count($_POST['files'])) {
$this->errorMsg("Unknown error.");
}
$error = array();
foreach ($_POST['files'] as $file) {
$file = path::normalize($file);
if (substr($file, 0, 1) == ".") {
continue;
}
$type = explode("/", $file);
$type = $type[0];
if ($type != $this->type) {
continue;
}
$path = "{$this->config['uploadDir']}/{$file}";
if (!$this->checkFilePath($path)) {
continue;
}
$base = basename($file);
$replace = array('file' => $this->htmlData($base));
$ext = file::getExtension($base);
if (!file_exists($path)) {
$error[] = $this->label("The file '{file}' does not exist.", $replace);
} elseif (substr($base, 0, 1) == ".") {
$error[] = $this->htmlData($base) . ": " . $this->label("File name shouldn't begins with '.'");
} elseif (!$this->validateExtension($ext, $type)) {
$error[] = $this->htmlData($base) . ": " . $this->label("Denied file extension.");
} elseif (file_exists("{$dir}/{$base}")) {
$error[] = $this->htmlData($base) . ": " . $this->label("A file or folder with that name already exists.");
} elseif (!is_readable($path) || !is_file($path)) {
$error[] = $this->label("Cannot read '{file}'.", $replace);
} elseif (!file::isWritable($path) || !@rename($path, "{$dir}/{$base}")) {
$error[] = $this->label("Cannot move '{file}'.", $replace);
} else {
if (function_exists("chmod")) {
@chmod("{$dir}/{$base}", $this->config['filePerms']);
}
$fromThumb = "{$this->thumbsDir}/{$file}";
if (is_file($fromThumb) && is_readable($fromThumb)) {
$toThumb = "{$this->thumbsTypeDir}/{$_POST['dir']}";
if (!is_dir($toThumb)) {
@mkdir($toThumb, $this->config['dirPerms'], true);
}
$toThumb .= "/{$base}";
@rename($fromThumb, $toThumb);
}
}
}
if (count($error)) {
return json_encode(array('error' => $error));
}
return true;
}
示例5: getFiles
protected function getFiles($dir)
{
$thumbDir = "{$this->config['uploadDir']}/{$this->config['thumbsDir']}/{$dir}";
$dir = "{$this->config['uploadDir']}/{$dir}";
$return = array();
$files = dir::content($dir, array('types' => "file"));
if ($files === false) {
return $return;
}
foreach ($files as $file) {
$img = new fastImage($file);
$type = $img->getType();
if ($type !== false) {
$size = $img->getSize($file);
if (is_array($size) && count($size)) {
$thumb_file = "{$thumbDir}/" . basename($file);
if (!is_file($thumb_file)) {
$this->makeThumb($file, false);
}
$smallThumb = $size[0] <= $this->config['thumbWidth'] && $size[1] <= $this->config['thumbHeight'] && in_array($type, array("gif", "jpeg", "png"));
} else {
$smallThumb = false;
}
} else {
$smallThumb = false;
}
$img->close();
$stat = stat($file);
if ($stat === false) {
continue;
}
$name = basename($file);
$ext = file::getExtension($file);
$types = $this->config['types'];
$types = explode(' ', $types['images'] . ' ' . $types['image']);
if (substr($name, 0, 1) == '.' && !$this->config['showHiddenFiles']) {
continue;
}
if ($this->type == 'images' && !in_array(strtolower($ext), $types)) {
continue;
}
$bigIcon = file_exists("themes/{$this->config['theme']}/img/files/big/{$ext}.png");
$smallIcon = file_exists("themes/{$this->config['theme']}/img/files/small/{$ext}.png");
$thumb = file_exists("{$thumbDir}/{$name}");
$return[] = array('name' => stripcslashes($name), 'size' => $stat['size'], 'mtime' => $stat['mtime'], 'date' => @strftime($this->dateTimeSmall, $stat['mtime']), 'readable' => is_readable($file), 'writable' => file::isWritable($file), 'bigIcon' => $bigIcon, 'smallIcon' => $smallIcon, 'thumb' => $thumb, 'smallThumb' => $smallThumb);
}
return $return;
}
示例6: get_couch_thumbs
static function get_couch_thumbs($filename, $dir = null)
{
if ($dir === null) {
// filename is a full path containing the folder
$dir = dirname($filename);
}
$filename = basename($filename);
$ext = file::getExtension($filename, false);
$name = strlen($ext) ? substr($filename, 0, -strlen($ext) - 1) : $filename;
$thumbs = dir::content($dir, array('types' => "file", 'pattern' => "/{$name}(?:-\\d{1,}x\\d{1,})\\.{$ext}/i"));
if ($thumbs === false) {
return array();
}
return $thumbs;
}
示例7: uploadImage
/**
* Action para upload de imagens para o servidor
* @param file $file imagem
* @param int $width Largura máxima da imagem
* @param int $heigth Altura máxima da imagem
* @param int $size Tamanho máximo da imagem
* @return string Nome da imagem ou erro caso ocorroa algum.
*/
private function uploadImage($file, $width, $heigth, $size, $name_img = NULL)
{
// Pega as dimensões da imagem
$dimensions = getimagesize($file->getTempName());
// Verifica se o arquivo é uma imagem
if (!preg_match("/^image\\/(pjpeg|jpeg|png|gif|bmp)\$/", $file->getRealType())) {
$data['message'] = "O Arquivo inserido não parece ser uma imagem!";
} elseif ($dimensions[0] > $width) {
// Verifica se a largura da imagem é maior que a largura permitida
$data['message'] = "A largura da imagem não deve ultrapassar " . $width . " pixels!";
} elseif ($dimensions[1] > $heigth) {
// Verifica se a altura da imagem é maior que a altura permitida
$data['message'] = "Altura da imagem não deve ultrapassar " . $heigth . " pixels!";
} elseif ($file->getSize() > $size) {
// Verifica se o tamanho da imagem é maior que o tamanho permitido
$data['message'] = "A imagem deve ter no máximo " . $size / 1024 . "MB!";
} else {
//Caso não haja erros faz o upload da imagem e salva a mesma no servidor
if ($name_img == NULL) {
$name_img = $this->getImgName() . "." . $file->getExtension();
}
//Verifica se a pasta public/img/users existe, se não existir, cria.
if (!file_exists(FOLDER_PROJECT . 'public/img/users')) {
mkdir(FOLDER_PROJECT . 'public/img/users');
}
$path_img = FOLDER_PROJECT . 'public/img/users/' . $name_img;
$file->moveTo($path_img);
return $name_img;
}
return $data;
}
示例8: getMime
public static function getMime($filename, $absolute_path = '')
{
// basic mimetypes
$mime_types = array('txt' => array('text/plain', 'document'), 'epub' => array('application/epub+zip', 'document'), 'png' => array('image/png', 'image'), 'jpeg' => array('image/jpeg', 'image'), 'jpg' => array('image/jpeg', 'image'), 'gif' => array('image/gif', 'image'), 'tiff' => array('image/tiff', 'image'), 'svg' => array('image/svg+xml', 'image'), 'ico' => array('image/x-icon', 'image'), 'webp' => array('image/webp', 'image'), 'zip' => array('application/zip', 'archive'), 'rar' => array('application/x-rar-compressed', 'archive'), 'exe' => array('application/x-msdownload', 'file'), 'mp3' => array('audio/mpeg', 'audio'), 'wav' => array('audio/x-wav', 'audio'), 'qt' => array('video/quicktime', 'video'), 'mov' => array('video/quicktime', 'video'), 'avi' => array('video/x-msvideo', 'video'), 'mp4' => array('video/mp4', 'video'), 'webm' => array('video/webm', 'video'), 'wmv' => array('video/x-ms-wmv', 'video'), 'swf' => array('application/x-shockwave-flash', 'flash'), 'flv' => array('video/x-flv', 'video'), 'pdf' => array('application/pdf', 'document'), 'psd' => array('image/vnd.adobe.photoshop', 'image'), 'doc' => array('application/msword', 'document'), 'docx' => array('application/msword', 'document'), 'rtf' => array('application/rtf', 'document'), 'xls' => array('application/vnd.ms-excel', 'document'), 'xlsx' => array('application/vnd.ms-excel', 'document'), 'ppt' => array('application/vnd.ms-powerpoint', 'document'), 'pptx' => array('application/vnd.ms-powerpoint', 'document'));
$ext = file::getExtension($filename);
if (function_exists('finfo_open') && !empty($absolute_path)) {
$finfo = finfo_open(FILEINFO_MIME);
$mimetype = finfo_file($finfo, $absolute_path);
finfo_close($finfo);
if (strpos($mimetype, ';') !== false) {
$mimetype = substr($mimetype, 0, strpos($mimetype, ';'));
}
$file_type = 'file';
foreach ($mime_types as $extension => $mime_info) {
if (strpos($mimetype, $mime_info[0]) !== false) {
$file_type = $mime_info[1];
break;
}
}
return array($mimetype, $file_type);
} else {
if (array_key_exists($ext, $mime_types)) {
return $mime_types[$ext];
} else {
return array('application/octet-stream', 'file');
}
}
}
示例9: getFiles
protected function getFiles($dir)
{
$thumbDir = "{$this->config['uploadDir']}/{$this->config['thumbsDir']}/{$dir}";
$dir = "{$this->config['uploadDir']}/{$dir}";
$return = array();
$files = dir::content($dir, array('types' => "file"));
if ($files === false) {
return $return;
}
foreach ($files as $file) {
$size = @getimagesize($file);
if (is_array($size) && count($size)) {
$thumb_file = "{$thumbDir}/" . basename($file);
if (!is_file($thumb_file)) {
$this->makeThumb($file, false);
}
$smallThumb = $size[0] <= $this->config['thumbWidth'] && $size[1] <= $this->config['thumbHeight'] && in_array($size[2], array(IMAGETYPE_GIF, IMAGETYPE_PNG, IMAGETYPE_JPEG));
} else {
$smallThumb = false;
}
$stat = stat($file);
if ($stat === false) {
continue;
}
$filename = basename($file);
if ('WIN' == substr(PHP_OS, 0, 3)) {
setlocale(LC_CTYPE, '');
// Resets the codepage to the system codepage so it can be properly retrieved
$codepage = 'Windows-' . trim(strstr(setlocale(LC_CTYPE, 0), '.'), '.');
if (function_exists('iconv')) {
$filename = iconv($codepage, 'UTF-8', $filename);
} elseif (function_exists('mb_convert_encoding')) {
$filename = mb_convert_encoding($filename, $codepage, 'UTF-8');
}
}
$name = $filename;
$ext = file::getExtension($file);
$bigIcon = file_exists("themes/{$this->config['theme']}/img/files/big/{$ext}.png");
$smallIcon = file_exists("themes/{$this->config['theme']}/img/files/small/{$ext}.png");
$thumb = file_exists("{$thumbDir}/{$name}");
$return[] = array('name' => stripcslashes($name), 'size' => $stat['size'], 'mtime' => $stat['mtime'], 'date' => @strftime($this->dateTimeSmall, $stat['mtime']), 'readable' => is_readable($file), 'writable' => file::isWritable($file), 'bigIcon' => $bigIcon, 'smallIcon' => $smallIcon, 'thumb' => $thumb, 'smallThumb' => $smallThumb);
}
return $return;
}
示例10: checkUploadedFile
protected function checkUploadedFile(array $aFile=null) {
$config = &$this->config;
$file = ($aFile === null) ? $this->file : $aFile;
if (!is_array($file) || !isset($file['name']))
return $this->label("Unknown error");
if (is_array($file['name'])) {
foreach ($file['name'] as $i => $name) {
$return = $this->checkUploadedFile(array(
'name' => $name,
'tmp_name' => $file['tmp_name'][$i],
'error' => $file['error'][$i]
));
if ($return !== true)
return "$name: $return";
}
return true;
}
$extension = file::getExtension($file['name']);
$typePatt = strtolower(text::clearWhitespaces($this->types[$this->type]));
// CHECK FOR UPLOAD ERRORS
if ($file['error'])
return
($file['error'] == UPLOAD_ERR_INI_SIZE) ?
$this->label("The uploaded file exceeds {size} bytes.",
array('size' => ini_get('upload_max_filesize'))) : (
($file['error'] == UPLOAD_ERR_FORM_SIZE) ?
$this->label("The uploaded file exceeds {size} bytes.",
array('size' => $this->get['MAX_FILE_SIZE'])) : (
($file['error'] == UPLOAD_ERR_PARTIAL) ?
$this->label("The uploaded file was only partially uploaded.") : (
($file['error'] == UPLOAD_ERR_NO_FILE) ?
$this->label("No file was uploaded.") : (
($file['error'] == UPLOAD_ERR_NO_TMP_DIR) ?
$this->label("Missing a temporary folder.") : (
($file['error'] == UPLOAD_ERR_CANT_WRITE) ?
$this->label("Failed to write file.") :
$this->label("Unknown error.")
)))));
// HIDDEN FILENAMES CHECK
elseif (substr($file['name'], 0, 1) == ".")
return $this->label("File name shouldn't begins with '.'");
// EXTENSION CHECK
elseif (!$this->validateExtension($extension, $this->type))
return $this->label("Denied file extension.");
// SPECIAL DIRECTORY TYPES CHECK (e.g. *img)
elseif (preg_match('/^\*([^ ]+)(.*)?$/s', $typePatt, $patt)) {
list($typePatt, $type, $params) = $patt;
if (class_exists("type_$type")) {
$class = "type_$type";
$type = new $class();
$cfg = $config;
$cfg['filename'] = $file['name'];
if (strlen($params))
$cfg['params'] = trim($params);
$response = $type->checkFile($file['tmp_name'], $cfg);
if ($response !== true)
return $this->label($response);
} else
return $this->label("Non-existing directory type.");
}
// IMAGE RESIZE
$gd = new gd($file['tmp_name']);
if (!$gd->init_error && !$this->imageResize($gd, $file['tmp_name']))
return $this->label("The image is too big and/or cannot be resized.");
return true;
}