本文整理汇总了PHP中getFileExt函数的典型用法代码示例。如果您正苦于以下问题:PHP getFileExt函数的具体用法?PHP getFileExt怎么用?PHP getFileExt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getFileExt函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isValidExt
/**
* check if a file extension is permitted
*
* @param string $filePath
* @param array $validExts
* @param array $invalidExts
* @return boolean
*/
function isValidExt($filePath, $validExts, $invalidExts = array())
{
$tem = array();
if (sizeof($validExts)) {
foreach ($validExts as $k => $v) {
$tem[$k] = strtolower(trim($v));
}
}
$validExts = $tem;
$tem = array();
if (sizeof($invalidExts)) {
foreach ($invalidExts as $k => $v) {
$tem[$k] = strtolower(trim($v));
}
}
$invalidExts = $tem;
if (sizeof($validExts) && sizeof($invalidExts)) {
foreach ($validExts as $k => $ext) {
if (array_search($ext, $invalidExts) !== false) {
unset($validExts[$k]);
}
}
}
if (sizeof($validExts)) {
if (array_search(strtolower(getFileExt($filePath)), $validExts) !== false) {
return true;
} else {
return false;
}
} elseif (array_search(strtolower(getFileExt($filePath)), $invalidExts) === false) {
return true;
} else {
return false;
}
}
示例2: directoryToArray
function directoryToArray($abs, $directory, $filterMap = NULL)
{
$assets = array();
$dir = $abs . $directory;
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if (!is_dir($dir . "/" . $file)) {
if ($filterMap) {
if (in_array(getFileExt($file), $filterMap)) {
if (fileIgnore($file)) {
$assets[basename($file)] = get_stylesheet_directory_uri() . $directory . $file;
}
}
} else {
if (fileIgnore($file)) {
$assets[basename($file)] = get_stylesheet_directory_uri() . $directory . $file;
}
}
}
}
}
closedir($handle);
}
return $assets;
}
示例3: init
public static function init($image, $width = 120, $height = 120, $isCheck = false)
{
if (!is_file($image)) {
return false;
}
//处理缩略图文件名
$imageExt = getFileExt($image);
$toImage = str_replace('.' . $imageExt, '_' . $width . '.' . $imageExt, $image);
if (is_file(ROOT . $toImage)) {
return $toImage;
} elseif ($isCheck) {
return false;
}
//获取图片信息
self::imageInfo($image);
//验证是否获取到信息
if (empty(self::$image_w) || empty(self::$image_h) || empty(self::$image_ext)) {
return false;
}
//如果图片比设置的小就直接返回
if (self::$image_w <= $width && self::$image_h <= $height) {
return $image;
}
//以原图做画布
$a = 'imagecreatefrom' . self::$image_ext;
$original = $a($image);
if (self::$image_w > self::$image_h) {
//宽 > 高
$crop_x = (self::$image_w - self::$image_h) / 2;
$crop_y = 0;
$crop_w = $crop_h = self::$image_h;
} else {
$crop_x = 0;
$crop_y = (self::$image_h - self::$image_w) / 2;
$crop_w = $crop_h = self::$image_w;
}
if (!$height) {
$height = floor(self::$image_h / (self::$image_w / $width));
$crop_x = 0;
$crop_y = 0;
$crop_w = self::$image_w;
$crop_h = self::$image_h;
}
$litter = imagecreatetruecolor($width, $height);
if (!imagecopyresampled($litter, $original, 0, 0, $crop_x, $crop_y, $width, $height, $crop_w, $crop_h)) {
return false;
}
//保存图片
$keep = 'image' . self::$image_ext;
$keep($litter, ROOT . $toImage);
//关闭图片
imagedestroy($original);
imagedestroy($litter);
return $toImage;
}
示例4: readJson
/**
* 解析json文件
*
* @param {string} $filePath 文件路径
* @param {boolean} $isRelatedToMock 是否相对于mock根目录
* @return {Object} json对象
*/
function readJson($filePath, $isRelatedToMock = false)
{
$ext = getFileExt($filePath);
if (empty($ext)) {
$filePath = $filePath . '.json';
}
if ($isRelatedToMock) {
$filePath = Conf::$rootDir . '/mock/' . $filePath;
} else {
$filePath = Conf::$scriptDir . '/' . $filePath;
}
$json = file_get_contents($filePath);
return json_decode($json, true);
}
示例5: recurseDirectoryWithFilter
function recurseDirectoryWithFilter(&$arrItems, $directory, $recursive, &$filterMap)
{
if ($handle = opendir($directory)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if (is_dir($directory . $file)) {
if ($recursive) {
recurseDirectoryWithFilter($arrItems, $directory . $file . "/", $recursive, $filterMap);
}
} else {
if (isset($filterMap[getFileExt($file)])) {
$arrItems[] = $directory . $file;
}
}
}
}
closedir($handle);
}
return $arrItems;
}
示例6: getCssFileList
function getCssFileList($cssDir)
{
$cssDir = rtrim($cssDir, '\\/') . '/';
$fileList = array();
//array('源css文件', '源css文件2'...));
if (is_dir($cssDir)) {
$dh = opendir($cssDir);
while (($file = readdir($dh)) !== false) {
if ($file != '.' && $file != '..') {
if (is_dir($cssDir . $file)) {
$fileList2 = getCssFileList($cssDir . $file);
$fileList = array_merge($fileList, $fileList2);
} else {
if (getFileExt($file) == 'css') {
$fileList[] = $cssDir . $file;
}
}
}
}
closedir($dh);
}
return $fileList;
}
示例7: uniqid
$history->add($sessionImageInfo);
if (CONFIG_SYS_DEMO_ENABLE) {
//demo only
if (isset($originalSessionImageInfo) && sizeof($originalSessionImageInfo)) {
$imagePath = $sessionDir . $originalSessionImageInfo['info']['name'];
} else {
$imagePath = $sessionDir . uniqid(md5(time())) . "." . getFileExt($_POST['path']);
}
} else {
if ($isSaveAsRequest) {
//save as request
//check save to folder if exists
if (isset($_POST['save_to']) && strlen($_POST['save_to'])) {
$imagePath = $originalImage;
} else {
$imagePath = addTrailingSlash(backslashToSlash($_POST['save_to'])) . $_POST['new_name'] . "." . getFileExt($_POST['path']);
}
if (!file_exists($_POST['save_to']) || !is_dir($_POST['save_to'])) {
$error = IMG_SAVE_AS_FOLDER_NOT_FOUND;
} elseif (file_exists($imagePath)) {
$error = IMG_SAVE_AS_NEW_IMAGE_EXISTS;
} elseif (!preg_match("/^[a-zA-Z0-9_\\- ]+\$/", $_POST['new_name'])) {
$error = IMG_SAVE_AS_ERR_NAME_INVALID;
}
} else {
//save request
$imagePath = $originalImage;
}
}
if ($image->saveImage($imagePath)) {
if (CONFIG_SYS_DEMO_ENABLE) {
示例8: _createDocs
function _createDocs(&$man, &$input)
{
$result = new Moxiecode_ResultSet("status,fromfile,tofile,message");
$config = $man->getConfig();
if (!$man->isToolEnabled("createdoc", $config)) {
trigger_error("{#error.no_access}", FATAL);
die;
}
for ($i = 0; isset($input["frompath" . $i]) && isset($input["toname" . $i]); $i++) {
$fromFile =& $man->getFile($input["frompath" . $i]);
$ext = getFileExt($fromFile->getName());
$toFile =& $man->getFile($input["topath" . $i], $input["toname" . $i] . '.' . $ext);
$toConfig = $toFile->getConfig();
if (checkBool($toConfig['general.demo'])) {
$result->add("FAILED", $man->encryptPath($fromFile->getAbsolutePath()), $man->encryptPath($toFile->getAbsolutePath()), "{#error.demo}");
continue;
}
if ($man->verifyFile($toFile, "createdoc") < 0) {
$result->add("FAILED", $man->encryptPath($fromFile->getAbsolutePath()), $man->encryptPath($toFile->getAbsolutePath()), $man->getInvalidFileMsg());
continue;
}
if (!$toFile->canWrite()) {
$result->add("FAILED", $man->encryptPath($fromFile->getAbsolutePath()), $man->encryptPath($toFile->getAbsolutePath()), "{#error.no_write_access}");
continue;
}
if (!checkBool($toConfig["filesystem.writable"])) {
$result->add("FAILED", $man->encryptPath($fromFile->getAbsolutePath()), $man->encryptPath($toFile->getAbsolutePath()), "{#error.no_write_access}");
continue;
}
if (!$fromFile->exists()) {
$result->add("FAILED", $man->encryptPath($fromFile->getAbsolutePath()), $man->encryptPath($toFile->getAbsolutePath()), "{#error.template_missing}");
continue;
}
if ($fromFile->copyTo($toFile)) {
// Replace title
$fields = $input["fields"];
// Replace all fields
if ($fields) {
// Read all data
$stream = $toFile->open('r');
$fileData = $stream->readToEnd();
$stream->close();
// Replace fields
foreach ($fields as $name => $value) {
$fileData = str_replace('${' . $name . '}', htmlentities($value), $fileData);
}
// Write file data
$stream = $toFile->open('w');
$stream->write($fileData);
$stream->close();
}
$result->add("OK", $man->encryptPath($fromFile->getAbsolutePath()), $man->encryptPath($toFile->getAbsolutePath()), "{#message.createdoc_success}");
} else {
$result->add("FAILED", $man->encryptPath($fromFile->getAbsolutePath()), $man->encryptPath($toFile->getAbsolutePath()), "{#error.createdoc_failed}");
}
}
return $result->toArray();
}
示例9: normalizeFileType
// We check if the data was submitted
if ($file && $type) {
// We define some stuffs
$type = normalizeFileType($type);
$dir = JAPPIX_BASE . '/app/' . $type . '/';
$path = $dir . $file;
// Read request headers
$if_modified_since = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? trim($_SERVER['HTTP_IF_MODIFIED_SINCE']) : null;
$if_modified_since = $if_modified_since ? strtotime($if_modified_since) : null;
// Define the real type if this is a "store" file
if ($type == 'store') {
// Rewrite path
$dir = JAPPIX_BASE . '/store/';
$path = $dir . $file;
// Extract the file extension
switch (getFileExt($file)) {
// CSS file
case 'css':
$type = 'stylesheets';
break;
// JS file
// JS file
case 'js':
$type = 'javascripts';
break;
// Audio file
// Audio file
case 'ogg':
case 'oga':
case 'mp3':
$type = 'sounds';
示例10: getFileExt
echo IMG_LBL_SAVE_AS;
?>
</th>
</tr>
</thead>
<tbody>
<tr>
<th>
<label><?php
echo IMG_LBL_NEW_NAME;
?>
</label>
</th>
<td>
<input type="text" id="new_name" class="input" name="new_name" value="" /> .<?php
echo getFileExt($path);
?>
</td>
</tr>
<tr>
<th>
<label><?php
echo IMG_LBL_SAVE_TO;
?>
</label>
</th>
<td>
<select class="input" name="save_to" id="save_to"></select>
</td>
</tr>
<tr>
示例11: get_src_img_object
function get_src_img_object($src_dir)
{
$src;
if (getFileExt($src_dir) == "gif") {
$src = ImageCreateFromGIF($src_dir);
} else {
if (getFileExt($src_dir) == "jpg" || getFileExt($src_dir) == "jpeg") {
$src = ImageCreateFromJPEG($src_dir);
} else {
if (getFileExt($src_dir) == "png") {
$src = ImageCreateFromPNG($src_dir);
}
}
}
return $src;
}
示例12: die
die("alert('You need to run the installer or rename/remove the \"install\" directory.');");
}
error_reporting(E_ALL ^ E_NOTICE);
require_once "../includes/general.php";
require_once '../classes/Utils/JSCompressor.php';
$compress = true;
// Some PHP installations seems to
// output the dir rather than the current file here
// it gets to /js/ instead of /js/index.php
$baseURL = $_SERVER["PHP_SELF"];
// Hmm, stange?
if (strpos($baseURL, 'default.php/') > 0 || strpos($baseURL, 'index.php/') > 0) {
$baseURL = $_SERVER["SCRIPT_NAME"];
}
// Is file, get dir
if (getFileExt($baseURL) == "php") {
$baseURL = dirname($baseURL);
}
// Remove trailing slash if it has any
if ($baseURL && $baseURL[strlen($baseURL) - 1] == '/') {
$baseURL = substr($baseURL, 0, strlen($baseURL) - 1);
}
// Remove any weird // or /// items
$baseURL = preg_replace('/\\/+/', '/', $baseURL);
if ($compress) {
$compressor = new Moxiecode_JSCompressor(array('expires_offset' => 3600 * 24 * 10, 'disk_cache' => true, 'cache_dir' => '_cache', 'gzip_compress' => true, 'remove_whitespace' => true, 'charset' => 'UTF-8'));
// Compress these
$compressor->addFile('mox.js');
$compressor->addFile('gz_loader.js');
$compressor->addContent("mox.defaultDoc = 'index.php';");
$compressor->addContent('mox.findBaseURL(/(\\/js\\/|\\/js\\/index\\.php)$/);');
示例13: getimagesize
$tmp = $_FILES['avatar']['tmp_name'];
$ecode = 0;
// check filesize
if (filesize($tmp) > $config->get('avatar_size') * 1000) {
$ecode = 1;
}
// check height & width
$size = getimagesize($tmp);
if ($size[0] > $config->get('avatar_height')) {
$ecode = 2;
}
if ($size[1] > $config->get('avatar_width')) {
$ecode = 3;
}
// check filetype
$ext = getFileExt($_FILES['avatar']['name']);
$ext = strtolower($ext);
$validExt = strtolower($config->get('avatar_types'));
$validExt = explode(',', $validExt);
if (!in_array($ext, $validExt)) {
$ecode = 4;
}
if ($ecode > 0) {
unlink($tmp);
jsRedirect('usercp.php?action=avatars&ecode=' . $ecode);
}
// everything is good, add the avatar
$file = time() . '-' . $user->id . '.' . $ext;
move_uploaded_file($tmp, './avatars/' . $file);
$id = $user->id;
$type = $_POST['type'];
示例14: switch
switch ($mimetype) {
case 'image/gif':
$ext = 'gif';
break;
case 'image/jpeg':
$ext = 'jpg';
break;
case 'image/png':
$ext = 'png';
break;
default:
$ext = null;
}
// Get the file extension if could not get it through MIME
if (!$ext) {
$ext = getFileExt($file_path);
}
if ($ext == 'gif' || $ext == 'jpg' || $ext == 'png') {
// Resize the image
resizeImage($file_path, $ext, 1024, 1024);
// Copy the image
$thumb = $file_path . '_thumb.' . $ext;
copy($file_path, $thumb);
// Create the thumbnail
if (resizeImage($thumb, $ext, 140, 105)) {
$thumb_xml = '<thumb>' . htmlspecialchars($location . 'store/share/' . $md5 . '_thumb.' . $ext) . '</thumb>';
}
}
// Return the path to the file
exit('<jappix xmlns=\'jappix:file:post\'>
<href>' . htmlspecialchars($location . '?m=download&file=' . $md5 . '&key=' . $key . '&ext=.' . $ext) . '</href>
示例15: echo
<th colspan="2"><?php echo IMG_LBL_SAVE_AS; ?></th>
</tr>
</thead>
<tbody>
<tr>
<th>
<label><?php echo IMG_LBL_NEW_NAME; ?></label>
</th>
<td>
<input type="text" id="new_name" class="input" name="new_name" value="" />
. <select id="ext" name="ext">
<?php
foreach(getValidTextEditorExts() as $v)
{
?>
<option value="<?php echo $v; ?>" <?php echo (strtolower($v) == strtolower(getFileExt($path))?'selected':''); ?>><?php echo $v; ?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<th>
<label><?php echo IMG_LBL_SAVE_TO; ?></label>
</th>
<td>
<select class="input" name="save_to" id="save_to">
</select>
</td>