本文整理汇总了PHP中getExtension函数的典型用法代码示例。如果您正苦于以下问题:PHP getExtension函数的具体用法?PHP getExtension怎么用?PHP getExtension使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getExtension函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: url
static function url($urls, $albumID = 0)
{
$error = false;
# Parse
$urls = str_replace(' ', '%20', $urls);
$urls = explode(',', $urls);
foreach ($urls as &$url) {
# Verify extension
$extension = getExtension($url);
if (!in_array(strtolower($extension), Photo::$validExtensions, true)) {
$error = true;
continue;
}
# Verify image
$type = @exif_imagetype($url);
if (!in_array($type, Photo::$validTypes, true)) {
$error = true;
continue;
}
$pathinfo = pathinfo($url);
$filename = $pathinfo['filename'] . '.' . $pathinfo['extension'];
$tmp_name = LYCHEE_DATA . $filename;
if (@copy($url, $tmp_name) === false) {
$error = true;
}
}
$import = Import::server($albumID, LYCHEE_DATA);
if ($error === false && $import === true) {
return true;
} else {
return false;
}
}
示例2: validate_language_form
function validate_language_form($data)
{
define("ICON_MAX_SIZE", "100");
$error = '';
if ($data['country'] == '' || empty($data['country'])) {
$error .= "Country field required!!<br>";
}
if ($data['language'] == '' || empty($data['language'])) {
$error .= "Language field required!!<br>";
}
if ($data['currency'] == '' || empty($data['currency'])) {
$error .= "Currency field required!!<br>";
}
$filename = stripslashes($data['icon']['name']);
if ($filename) {
$extension = getExtension($filename);
$extension = strtolower($extension);
if ($extension != "jpg" && $extension != "jpeg" && $extension != "png" && $extension != "gif") {
$error .= "Upload language icon unknown extension!!<br>";
} else {
$size = $data['icon']['size'];
if ($size > ICON_MAX_SIZE * 1024) {
$error .= "Upload language icon exceeded the size limit!!<br>";
}
list($width, $height) = getimagesize($data['icon']['tmp_name']);
if ($width > 50 || $height > 50) {
$error .= "Upload language icon size must 50 * 50!!<br>";
}
}
} else {
$error .= "Upload language icon field required!!<br>";
}
return $error;
}
示例3: hinzufuegen
function hinzufuegen($bildseite, $datenbank)
{
if (hinzufuegenVariablenVorhanden()) {
if ($extension = getExtension()) {
// ZeigenAb wurde angegeben
if (strtotime($_POST["zeigenAb"]) !== false) {
// ZeigenBis wurde angegeben
if (strtotime($_POST["zeigenBis"]) !== false) {
$bildseite->create($datenbank, $extension, $_POST["beschriftung"], $_POST["layout"], date("Y-m-d H:i:s", strtotime($_POST["zeigenAb"])), date("Y-m-d H:i:s", strtotime($_POST["zeigenBis"])));
// ZeigenBis wurde nicht angegeben
} else {
$bildseite->create($datenbank, $extension, $_POST["beschriftung"], $_POST["layout"], date("Y-m-d H:i:s", strtotime($_POST["zeigenAb"])));
}
// ZeigenAb wurde nicht angegeben
} else {
$bildseite->create($datenbank, $extension, $_POST["beschriftung"], $_POST["layout"]);
}
dateiVerschieben($bildseite->id, $extension);
zurueck();
} else {
echo "Datei wurde nicht erfolgreich hochgeladen :/";
}
} else {
echo "Nicht alle oder ungültige Daten übertragen :/";
}
}
示例4: boot
/**
* Bootstraps the application.
*
* This method is called after all services are registers
* and should be used for "dynamic" configuration (whenever
* a service must be requested).
*/
public function boot(Application $app)
{
if (isset($app['translator'])) {
$paths = $app['resources']->getPaths();
$app['translator']->addLoader('yml', new TranslationLoader\YamlFileLoader());
// Directory to look for translation file(s)
$translationDir = $paths['apppath'] . '/resources/translations/' . $app['locale'];
if (is_dir($translationDir)) {
$iterator = new \DirectoryIterator($translationDir);
/**
* @var \SplFileInfo $fileInfo
*/
foreach ($iterator as $fileInfo) {
if ($fileInfo->isFile() && getExtension($fileInfo->getFilename()) == "yml") {
$fnameParts = explode(".", $fileInfo->getFilename());
$domain = $fnameParts[0];
$app['translator']->addResource('yml', $fileInfo->getRealPath(), $app['locale'], $domain);
}
}
}
// Load fallback for infos domain
$infosfilename = dirname(dirname(dirname(__DIR__))) . '/resources/translations/en/infos.en.yml';
if (is_readable($infosfilename)) {
$app['translator']->addResource('yml', $infosfilename, 'en', 'infos');
}
}
}
示例5: findFilesHelper
function findFilesHelper($additional, &$files, $term = '', $extensions = array())
{
$basefolder = __DIR__ . '/../../files/';
$currentfolder = realpath($basefolder . '/' . $additional);
$dir = dir($currentfolder);
$ignored = array('.', '..', '.DS_Store', '.gitignore', '.htaccess');
while (false !== ($entry = $dir->read())) {
if (in_array($entry, $ignored) || substr($entry, 0, 2) == '._') {
continue;
}
if (is_file($currentfolder . '/' . $entry) && is_readable($currentfolder . '/' . $entry)) {
// Check for 'term'..
if (!empty($term) && strpos(strtolower($currentfolder . '/' . $entry), $term) === false) {
continue;
// skip this one..
}
// Check for correct extensions..
if (!empty($extensions) && !in_array(getExtension($entry), $extensions)) {
continue;
// Skip files without correct extension..
}
if (!empty($additional)) {
$filename = $additional . '/' . $entry;
} else {
$filename = $entry;
}
$files[] = $filename;
}
if (is_dir($currentfolder . '/' . $entry)) {
findFilesHelper($additional . '/' . $entry, $files, $term, $extensions);
}
}
$dir->close();
}
示例6: resizeImage
function resizeImage($filename, $newfilename, $max_width = '', $max_height = '', $withSampling = true)
{
// if($newfilename=="")
// $newfilename=$filename;
// Get new sizes
list($width, $height) = getimagesize($filename);
if ($max_width == '' && $max_height == '') {
exit("You must set a max height or width");
}
if ($max_width != '') {
$percent = $max_width / $width;
} else {
if ($max_height != '') {
$percent = $max_height / $height;
}
}
//-- dont resize if the width of the image is smaller or equal than the new size.
// if($width<=$max_width)
// $max_width=$width;
// $percent = $max_width/$width;
$newwidth = $width * $percent;
$newheight = $height * $percent;
// if($max_height=='') {
// } else
// $newheight = $max_height;
// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$ext = strtolower(getExtension($filename));
// print $ext;
// exit();
if ($ext == 'jpg' || $ext == 'jpeg') {
$source = imagecreatefromjpeg($filename);
} else {
if ($ext == 'gif') {
$source = imagecreatefromgif($filename);
} else {
if ($ext == 'png') {
$source = imagecreatefrompng($filename);
}
}
}
// Resize
if ($withSampling) {
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
} else {
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}
// imagedestroy($thumb);
// Output
if ($ext == 'jpg' || $ext == 'jpeg') {
return imagejpeg($thumb, $newfilename);
}
if ($ext == 'gif') {
return imagegif($thumb, $newfilename);
}
if ($ext == 'png') {
return imagepng($thumb, $newfilename);
}
}
示例7: changeFileNameImage
function changeFileNameImage($filename)
{
$file = getFilename($filename);
$str = strtotime(date('Y-m-d H:i:s'));
$fileNameAfter = $file . '-' . $str;
$extension = getExtension($filename);
return $fileNameAfter . '.' . $extension;
}
示例8: check_upload_extension
function check_upload_extension($filename,$allow_list){
$sExtension = getExtension($filename);
$allow_arr = explode(",", $allow_list);
$pass = 0;
for($i=0; $i<count($allow_arr); $i++){
if($sExtension == $allow_arr[$i]) $pass = 1;
}
return $pass;
}
示例9: post_image
function post_image()
{
//$errors=0;
//checks if the form has been submitted
if (isset($_POST['Submit'])) {
//reads the name of the file the user submitted for uploading
$image = $_FILES['image']['name'];
//echo $image;
//if it is not empty
if ($image) {
//get the original name of the file from the clients machine
$filename = stripslashes($_FILES['image']['name']);
//get the extension of the file in a lower case format
$extension = getExtension($filename);
$extension = strtolower($extension);
//if it is not a known extension, we will suppose it is an error and will not upload the file,
//otherwise we will do more tests
//echo $filename;
//echo $extension;
if ($extension != "jpg" && $extension != "jpeg" && $extension != "png" && $extension != "gif") {
//print error message
echo '<h1>Unknown extension!</h1>';
//$errors=1;
return false;
} else {
//get the size of the image in bytes
//$_FILES['image']['tmp_name'] is the temporary filename of the file
//in which the uploaded file was stored on the server
$size = filesize($_FILES['image']['tmp_name']);
//compare the size with the maxim size we defined and print error if bigger
if ($size > MAX_SIZE * 1024) {
echo '<h1>File over size limit (1.5 mb).</h1>';
$errors = 1;
return false;
}
$image_name = time() . make_random() . '.' . $extension;
//echo "image name var ".$image_name;
//the new name will be containing the full path where will be stored (images folder)
$newname = "img_db/" . $image_name;
//we verify if the image has been uploaded, and print error instead
$copied = copy($_FILES['image']['tmp_name'], $newname);
if (!$copied) {
echo '<h1>Copy unsuccessfull!</h1>';
$errors = 1;
return false;
} else {
//echo "accepted";
$GLOBALS['newname'] = $newname;
return true;
}
}
//else for extension known.
}
//make sure image is not empty
}
//recheck is POST isset
}
示例10: upload
function upload($file, $allow = array('gif', 'png', 'jpeg', 'jpg'))
{
//1.对$file进行判断,如果不是数组就不存在上传文件
if (!is_array($file)) {
return array(false, '当前不是上传的文件信息!');
}
//2. 判断文件是否上传成功
//定义一个错误字符串
$errorinfo = '';
switch ($file['error']) {
case 1:
$errorinfo = '文件大小超过限制,最大上传大小为' . ini_get('upload_max_filesize');
break;
case 2:
$errorinfo = '文件超过浏览器允许大小';
break;
case 3:
$errorinfo = '文件只上传成功一部分';
break;
case 4:
$errorinfo = '没有选中要上传的文件';
break;
case 6:
$errorinfo = '找不到服务器临时目录';
break;
case 7:
$errorinfo = '文件上传路径不可写';
break;
}
if ($errorinfo) {
return array(false, $errorinfo);
}
//3.判断文件类型
$extension = getExtension($file['name']);
//3.1 判断文件后缀是否存在
if (!$extension) {
//文件后缀名不存在
return array(false, '当前文件没有后缀名!');
}
//3.2 当前文件是否允许上传
if (!in_array($extension, $allow)) {
return array(false, '当前文件类型不允许上传!');
}
//4.上传文件
//4.1重命名文件:获取一个随机的文件名字
$filename = getRanomFilename();
//拼凑问价全名
$filename .= '.' . $extension;
//4.2移动文件
if (!@move_uploaded_file($file['tmp_name'], $filename)) {
//写错误日志
return array(false, '文件上传失败');
} else {
return getcwd() . '\\' . $filename;
}
}
示例11: generateThumbnail
static function generateThumbnail($item)
{
$stats = self::generateStats($item['ups'], $item['favs'], $item['downs'], $item['safety']);
$extension = getExtension($item['filename']);
if ($extension == 'webm') {
$item['filename'] .= '.png';
$extension = 'png';
}
return intermix(self::$code, [$item['media_ID'], $item['filename'], $extension, $stats]);
}
示例12: allowedUpload
/**
* Checks if a given file is acceptable for upload.
*/
public function allowedUpload($originalFilename)
{
// no UNIX-hidden files
if ($originalFilename[0] === '.') {
return false;
}
// only whitelisted extensions
$extension = strtolower(getExtension($originalFilename));
$allowedExtensions = $this->getAllowedUploadExtensions();
return in_array($extension, $allowedExtensions);
}
示例13: url
public function url($urls, $albumID = 0)
{
# Check dependencies
self::dependencies(isset($this->database, $urls));
# Call plugins
$this->plugins(__METHOD__, 0, func_get_args());
$error = false;
# Parse URLs
$urls = str_replace(' ', '%20', $urls);
$urls = explode(',', $urls);
foreach ($urls as &$url) {
# Validate photo type and extension even when $this->photo (=> $photo->add) will do the same.
# This prevents us from downloading invalid photos.
# Verify extension
$extension = getExtension($url);
if (!in_array(strtolower($extension), Photo::$validExtensions, true)) {
$error = true;
Log::error($this->database, __METHOD__, __LINE__, 'Photo format not supported (' . $url . ')');
continue;
}
# Verify image
$type = @exif_imagetype($url);
if (!in_array($type, Photo::$validTypes, true)) {
$error = true;
Log::error($this->database, __METHOD__, __LINE__, 'Photo type not supported (' . $url . ')');
continue;
}
$pathinfo = pathinfo($url);
$filename = $pathinfo['filename'] . '.' . $pathinfo['extension'];
$tmp_name = LYCHEE_DATA . $filename;
if (@copy($url, $tmp_name) === false) {
$error = true;
Log::error($this->database, __METHOD__, __LINE__, 'Could not copy file (' . $tmp_name . ') to temp-folder (' . $tmp_name . ')');
continue;
}
# Import photo
if (!$this->photo($tmp_name, $albumID)) {
$error = true;
Log::error($this->database, __METHOD__, __LINE__, 'Could not import file: ' . $tmp_name);
continue;
}
}
# Call plugins
$this->plugins(__METHOD__, 1, func_get_args());
if ($error === false) {
return true;
}
return false;
}
示例14: getErrors
public function getErrors($postarr = array())
{
//Получение ошибок при регистрации
$this->name = $postarr['name'];
$this->surname = $postarr['surname'];
$this->email = $postarr['email'];
$this->login = $postarr['login'];
$this->password = $postarr['password'];
$this->confirmpass = $postarr['confirmpass'];
$this->age = $postarr['age'];
$this->filename = $postarr['filename'];
$this->filesize = $postarr['filesize'];
if (!empty($this->filename)) {
//проверяем расширение файла
function getExtension($filename)
{
return end(explode(".", $filename));
}
$extension = getExtension($this->filename);
//Проверка, существует ли пользователь с таким логином
}
$errors = array();
if (empty($this->login)) {
array_push($errors, "Заполните поле логин");
} elseif (strlen($this->login) < 3) {
array_push($errors, "Логин слишком короткий. Логин должен быть длиннее 3 символов");
} elseif (empty($this->password)) {
array_push($errors, "Заполните поле пароль");
} elseif (empty($this->confirmpass)) {
array_push($errors, "Заполните поле подтверждение пароля");
} elseif (empty($this->email)) {
array_push($errors, "Заполните поле Email");
} elseif ($this->password != $this->confirmpass) {
array_push($errors, "Пароли не совпадают");
} elseif (strlen($this->password) < 6) {
array_push($errors, "Пароль слишком короткий. Пароль должен быть длиннее 6 символов");
} elseif ($this->age > 99) {
array_push($errors, "Возраст введен не корректно.");
} elseif (!is_numeric($this->age)) {
array_push($errors, "Возраст должен быть указан в цифрах");
} elseif ($this->filesize > 1048576 * 5) {
array_push($errors, "Размер файла должен быть меньше 5 мегабайт");
} elseif (isset($extension)) {
if ($extension != 'jpg' && $extension != 'png' && $extension != 'gif') {
array_push($errors, "Допускается загрузка файлов в формате gif/jpg/png");
}
}
return $errors;
}
示例15: boot
/**
* Bootstraps the application.
*
* This method is called after all services are registers
* and should be used for "dynamic" configuration (whenever
* a service must be requested).
*/
public function boot(\Silex\Application $app)
{
if (isset($app['translator'])) {
$loaders = array('csv' => new TranslationLoader\CsvFileLoader(), 'ini' => new TranslationLoader\IniFileLoader(), 'mo' => new TranslationLoader\MoFileLoader(), 'php' => new TranslationLoader\PhpFileLoader(), 'xlf' => new TranslationLoader\XliffFileLoader(), 'yml' => new TranslationLoader\YamlFileLoader());
$registeredLoaders = array();
// Directory to look for translation file(s)
$translationDir = dirname(dirname(__DIR__)) . '/resources/translations/' . $app['locale'];
if (is_dir($translationDir)) {
$iterator = new \DirectoryIterator($translationDir);
/**
* @var \SplFileInfo $fileInfo
*/
foreach ($iterator as $fileInfo) {
if ($fileInfo->isFile()) {
$extension = getExtension($fileInfo->getFilename());
// $extension = $fileInfo->getExtension(); -- not available before 5.3.7.
if (array_key_exists($extension, $loaders)) {
if (!array_key_exists($extension, $registeredLoaders)) {
// TranslationFileLoader not yet registered
$app['translator']->addLoader($extension, $loaders[$extension]);
}
// There's a file, there's a loader, let's try
$fnameParts = explode(".", $fileInfo->getFilename());
$domain = $fnameParts[0];
$app['translator']->addResource($extension, $fileInfo->getRealPath(), $app['locale'], $domain);
}
}
}
}
// load fallback for infos domain
$locale_fb = $app['locale_fallback'];
$translationDir = dirname(dirname(__DIR__)) . '/resources/translations/' . $locale_fb;
if (is_dir($translationDir)) {
$extension = 'yml';
$domain = 'infos';
$infosfilename = "{$translationDir}/{$domain}.{$locale_fb}.{$extension}";
if (is_readable($infosfilename)) {
if (array_key_exists($extension, $loaders)) {
if (!array_key_exists($extension, $registeredLoaders)) {
// TranslationFileLoader not yet registered
$app['translator']->addLoader($extension, $loaders[$extension]);
}
$app['translator']->addResource($extension, $infosfilename, $locale_fb, $domain);
}
}
}
}
}