本文整理汇总了PHP中file_extension函数的典型用法代码示例。如果您正苦于以下问题:PHP file_extension函数的具体用法?PHP file_extension怎么用?PHP file_extension使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了file_extension函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: pleac_Splitting_a_Filename_into_Its_Component_Parts
function pleac_Splitting_a_Filename_into_Its_Component_Parts()
{
$base = basename($path);
$dir = dirname($path);
// PHP's equivalent to Perl's 'fileparse'
$pathinfo = pathinfo($path);
$base = $pathinfo['basename'];
$dir = $pathinfo['dirname'];
$ext = $pathinfo['extension'];
// ----------------------------
$path = '/usr/lib/libc.a';
printf("dir is %s, file is %s\n", dirname($path), basename($path));
// ------------
$path = '/usr/lib/libc.a';
$pathinfo = pathinfo($path);
printf("dir is %s, name is %s, extension is %s\n", $pathinfo['dirname'], $pathinfo['basename'], $pathinfo['extension']);
// ----------------------------
// Handle Mac example as a simple parse task. However, AFAIK, 'pathinfo' is cross-platform,
// so should handle file path format differences transparently
$path = 'Hard%20Drive:System%20Folder:README.txt';
$macp = array_combine(array('drive', 'folder', 'filename'), split("\\:", str_replace('%20', ' ', $path)));
$macf = array_combine(array('name', 'extension'), split("\\.", $macp['filename']));
printf("dir is %s, name is %s, extension is %s\n", $macp['drive'] . ':' . $macp['folder'], $macf['name'], '.' . $macf['extension']);
// ----------------------------
// Not really necessary since we have, 'pathinfo', but better matches Perl example
function file_extension($filename, $separator = '.')
{
return end(split("\\" . $separator, $filename));
}
// ----
echo file_extension('readme.txt') . "\n";
}
开发者ID:Halfnhav4,项目名称:pfff,代码行数:32,代码来源:Splitting_a_Filename_into_Its_Component_Parts.php
示例2: __construct
/**
* Instantiate the translation language
*
* @param TranslationLanguage $a_language
* @throws GenericException If the file is inexistant or invalid
*/
public function __construct(TranslationLanguage $a_language)
{
$this->locale_string = array();
$this->language = $a_language;
if (file_exists($this->language->file_path)) {
if (file_extension($this->language->file_path) == "json") {
$file = fopen($this->language->file_path, 'r');
$content = fread($file, filesize($this->language->file_path));
$content = json_decode($content);
$array = array();
$indexes = array();
foreach ($content as $part => $sub_content) {
$indexes[$part] = $sub_content;
}
if (isset($indexes['locale'])) {
foreach ($indexes['locale'] as $key => $value) {
$array[$key] = $value;
}
} else {
$array['datehour'] = "%x %H:%M";
$array['date'] = "%x";
$array['hour'] = "%H:%M";
}
$this->locale_entries = $array;
} else {
throw new GenericException("Invalid File");
}
} else {
throw new GenericException("Inexistant File");
}
}
开发者ID:youmy001,项目名称:apine-framework,代码行数:37,代码来源:TranslationLocale.php
示例3: uploadAttributes
function uploadAttributes($file_name, $file_size, $path, $id = '')
{
$access_key_id = $this->getOption('AWSAccessKeyID');
$secret_access_key = $this->getOption('AWSSecretAccessKey');
$bucket = $this->getOption('S3Bucket');
if (!($bucket && $access_key_id && $secret_access_key)) {
throw new UnexpectedValueException('Configuration options AWSAccessKeyID, AWSSecretAccessKey, SQSQueueURL, S3Bucket required');
}
$extension = file_extension($file_name);
$mime = mime_from_path($file_name);
if (!($mime && $extension)) {
throw new UnexpectedValueException('Could not determine mime type or extension of: ' . $file_name);
}
if (!$id) {
$id = unique_id($mime);
}
$s3_options = array();
$s3_options['bucket'] = $bucket;
$s3_options['AWSAccessKeyId'] = $access_key_id;
$s3_options['AWSSecretAccessKey'] = $secret_access_key;
$s3_options['uniq_id'] = $id;
$s3_options['path'] = $path . '.' . $extension;
$s3_options['mime'] = $mime;
$s3data = s3_upload_data($s3_options);
$result = '';
if (!empty($s3data)) {
$s3data['mime'] = $mime;
$s3data['keyid'] = $access_key_id;
//$s3data['id'] = $id;
foreach ($s3data as $k => $v) {
$result .= ' ' . $k . '="' . $v . '"';
}
}
return $result;
}
开发者ID:ronniebrito,项目名称:moodle_moviemasher,代码行数:35,代码来源:S3.php
示例4: createScriptObjectFromFilename
function createScriptObjectFromFilename ($pagename, $fname, $data='') {
$ext = file_extension($fname);
switch ($ext) {
case 'gpt': return new GnuplotScriptObject($pagename, $fname, true);
}
return false;
}
开发者ID:hexerei-software,项目名称:XOX-Framework,代码行数:7,代码来源:ScriptObjectFactory.class.php
示例5: test_file_extension
function test_file_extension()
{
assert_equal(file_extension('my_file'), '');
assert_equal(file_extension('my_file.txt'), 'txt');
assert_equal(file_extension('my_file.html.php'), 'php');
assert_equal(file_extension('my_file.JPG'), 'JPG');
}
开发者ID:karupanerura,项目名称:isucon4,代码行数:7,代码来源:file.php
示例6: process
function process ($fo, $out) {
if (!file_exists($fo))
die("file '$fo' not found");
$format = file_extension($out);
if ($format != 'ps' && $format != 'pdf')
$format = 'pdf';
RunTool('fo2rtf', "FO=$fo OUT=$out", 'pipe-callback', array('FO2RTF', 'messageCallback'));
}
开发者ID:hexerei-software,项目名称:XOX-Framework,代码行数:8,代码来源:FO2RTF.class.php
示例7: getBoundingBox
function getBoundingBox ($fname) {
$ext = file_extension($fname);
switch ($ext) {
case 'eps': return getEPSBoundingBox($fname);
case 'pdf': return getPDFBoundingBox($fname);
}
return false;
}
开发者ID:hexerei-software,项目名称:XOX-Framework,代码行数:8,代码来源:eps_pdf_tools.inc.php
示例8: show_file_name
function show_file_name($file_name, $charnum)
{
if (strlen($file_name) <= $charnum + 7) {
return $file_name;
} else {
return substr($file_name, 0, $charnum) . '.......' . file_extension($file_name);
}
}
开发者ID:soarmorrow,项目名称:ci-kindergarden,代码行数:8,代码来源:template_helper.php
示例9: getBoundingBox
function getBoundingBox ($fname) {
$ext = file_extension($fname);
if ($ext == 'eps')
return getEPSBoundingBox($fname);
if ($ext == 'pdf')
return getPDFBoundingBox($fname);
return false;
}
开发者ID:hexerei-software,项目名称:XOX-Framework,代码行数:8,代码来源:pdftools.inc.php
示例10: redirect
function redirect($url_path)
{
$this->load->model('link_model');
$link = $this->link_model->get_links(array('url_path' => $url_path));
if (empty($link)) {
return show_404($url_path);
}
$link = $link[0];
// get serialized url/groups data
$data = unserialize($link['parameter']);
if (empty($data)) {
return show_error('Invalid link.');
}
// if this is an absolute link, we'll try and make it relative
if (strpos($data['url'], $this->config->item('base_url')) === 0) {
// it begins with the URL, so we can just strip this to get a relative path
$data['url'] = substr_replace($data['url'], '', 0, strlen($this->config->item('base_url')));
} elseif (strpos($data['url'], FCPATH) === 0) {
$data['url'] = substr_replace($data['url'], '', 0, strlen(FCPATH));
}
// add APPPATH to make this an absolute path
$data['url'] = FCPATH . $data['url'];
// check permissions
if (!$this->user_model->in_group($data['groups'])) {
return show_error('Insufficient access privileges.');
} else {
// load and return file
$this->load->helper('file_extension');
// set filename
$filename = (isset($data['filename']) and !empty($data['filename'])) ? $data['filename'] : $link['url_path'] . '.' . file_extension($data['url']);
$extension = file_extension($data['url']);
// get the mime type
include APPPATH . 'config/mimes.php';
if (!isset($mimes[$extension])) {
die(show_error('Failed to retrieve mime-type data for file extension "' . $extension . '".'));
}
$mime_type = $mimes[$extension];
// some mime types are arrays...
if (is_array($mime_type)) {
$mime_type = $mime_type[0];
}
// don't limit to small files
set_time_limit(0);
header("Pragma: public");
// required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private", FALSE);
// required for certain browsers
header("Content-Type: " . $mime_type);
header("Content-Disposition: attachment; filename=\"" . $filename . "\";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . filesize($data['url']));
readfile($data['url'], "r");
die;
}
}
开发者ID:Rotron,项目名称:hero,代码行数:57,代码来源:protected_link.php
示例11: get_mimetype
/**
* Return the possible MIME type of a function
* @param string filename The name of the file to be delt with
* @return string Hopefully the MIME type of the file
* @author Peter Goodman
*/
function get_mimetype($filename)
{
global $mimetypes;
$ext = file_extension($filename);
$mimetype = $mimetypes[FALSE];
if (isset($mimetypes[$ext])) {
$mimetype = $mimetypes[$ext];
}
return $mimetype;
}
开发者ID:BackupTheBerlios,项目名称:k4bb-svn,代码行数:16,代码来源:mimetype.php
示例12: image_show_jpeg_only
function image_show_jpeg_only()
{
$ext = file_extension(params(0));
$filename = option('public_dir').params(0);
if(params('size') == 'thumb') $filename .= ".thb";
$filename .= '.jpg';
if(!file_exists($filename)) halt(NOT_FOUND, "$filename doesn't exists");
render_file($filename);
}
开发者ID:htom78,项目名称:limonade,代码行数:10,代码来源:index.php
示例13: accept_upload
function accept_upload(&$upload)
{
$this->upload['filename'] = trim($upload['name']);
$this->upload['filesize'] = intval($upload['size']);
$this->upload['location'] = trim($upload['tmp_name']);
$this->upload['extension'] = strtolower(file_extension($this->upload['filename']));
$this->upload['thumbnail'] = '';
$this->upload['filestuff'] = '';
return true;
}
开发者ID:hungnv0789,项目名称:vhtm,代码行数:10,代码来源:default_data_functions.php
示例14: file
public function file($filename)
{
$format = file_extension($filename, $id);
if ($id === 'list') {
return $this->index($format);
}
$repo = getRepository($this->repository);
$instance = $repo->get($this->model, $id);
$data = $repo->export($this->model, $instance, $this->maxRecursion);
return $this->format($data, $format);
}
开发者ID:sledgehammer,项目名称:mvc,代码行数:11,代码来源:CrudFolder.php
示例15: subirArchivo
/**
* Sube un archivo a la carpeta uploads
* @param unknown_type $arr_file_desc
* @param unknown_type $destino
* @param unknown_type $name
*/
function subirArchivo($arr_file_desc, $destino = null, $name = null)
{
$arr_file = array();
$file_extension = file_extension($arr_file_desc['name']);
if ($destino == null) {
$dia = date("j");
$mes = date("n");
$anyo = date("Y");
$new_relative_path = $anyo . BARRA_SERVIDOR . $mes . BARRA_SERVIDOR . $dia;
} else {
$new_relative_path = $destino;
}
if ($name != null) {
$new_file_name = $name;
} else {
$new_file_name = str_replace("." . $file_extension, "", $arr_file_desc['name']);
}
// Creamos la ruta de carpetas
createPath($new_relative_path);
// Si existe el archivo, con un contador cambio el nombre hasta que deje de existir
$cont = 0;
while (file_exists(UPLOAD_DIR . BARRA_SERVIDOR . $new_relative_path . BARRA_SERVIDOR . $new_file_name . "." . $file_extension)) {
$cont++;
$new_file_name .= $cont;
}
if (file_exists($arr_file_desc['tmp_name'])) {
if (!copy($arr_file_desc['tmp_name'], UPLOAD_DIR . BARRA_SERVIDOR . $new_relative_path . BARRA_SERVIDOR . $new_file_name . "." . $file_extension)) {
print "Error, no ha sido posible la copia del archivo";
} else {
//borro el archivo temporal
unlink($arr_file_desc['tmp_name']);
}
} else {
header('Content-type: application/json');
//objeto json que devolverá la respuesta
$jsondata = array();
$jsondata['error'] = true;
$jsondata['msg'] = "No se ha podido subir el archivo, intentelo de nuevo o contacte con su administrador.";
echo json_encode($jsondata);
exit;
}
$new_file_path = $new_relative_path . BARRA_SERVIDOR . $new_file_name . "." . $file_extension;
$origen_dir = UPLOAD_DIR . BARRA_SERVIDOR . substr($new_file_path, 0, strrpos($new_file_path, BARRA_SERVIDOR)) . BARRA_SERVIDOR;
$nombre_archivo = substr($new_file_path, strrpos($new_file_path, BARRA_SERVIDOR) + 1);
$nombre_sin_extension = substr($nombre_archivo, 0, strrpos($nombre_archivo, "."));
$extension = substr($new_file_path, strrpos($new_file_path, ".") + 1);
//si es una imagen, creo una más pequeña para agilizar la carga con thumbnails
if ($extension == "jpg" || $extension == "gif" || $extension == "png") {
//$info = getimagesize ($new_file_path);
img_resize($origen_dir . $nombre_archivo, THUMBNAIL_WIDTH, $origen_dir, $nombre_sin_extension . "." . $extension, THUMBNAIL_HEIGHT);
}
// Devuelvo la ruta sin la carpeta padre por si se cambia en la configuracion
return $new_file_path;
}
开发者ID:migumuno,项目名称:Core,代码行数:60,代码来源:functions.php
示例16: __construct
/**
* Construct the Translation handler
* Extract string from the translation file
*
* @param TranslationLanguage $a_language
* @throws GenericException If the file is inexistant or invalid
*/
public function __construct(TranslationLanguage $a_language)
{
$this->language = $a_language;
$this->locale = new TranslationLocale($this->language);
if (file_exists($this->language->file_path)) {
if (file_extension($this->language->file_path) != "json") {
throw new GenericException("Invalid File");
}
} else {
throw new GenericException("Inexistant File");
}
}
开发者ID:youmy001,项目名称:apine-framework,代码行数:19,代码来源:Translation.php
示例17: upload
function upload($input_name, $destination_name, $allowed_filetypes)
{
$ret = TRUE;
if ($ret && !is_writeable(dirname($destination_name))) {
$ret = FALSE;
}
$filetype = file_extension($_FILES[$input_name]['name']);
if ($ret && !in_array($filetype, $allowed_filetypes)) {
$ret = FALSE;
}
if ($ret && !@move_uploaded_file($_FILES[$input_name]['tmp_name'], $destination_name)) {
$ret = FALSE;
}
return $ret;
}
开发者ID:BackupTheBerlios,项目名称:k4bb-svn,代码行数:15,代码来源:images.class.php
示例18: upload_file_ftp
function upload_file_ftp($host, $name, $pass, $var, $upload_path, $file_name_prefix)
{
if (isset($_FILES[$var]) && $_FILES[$var]['error'] == UPLOAD_ERR_OK && is_file_type('firmware', $_FILES[$var]['name'])) {
$ext = file_extension($_FILES[$var]['name']);
if ($ext == 'jpeg') {
$ext = 'jpg';
}
$conn_id = ftp_connect($host);
$login_result = ftp_login($conn_id, $name, $pass);
ftp_pasv($conn_id, true);
if (ftp_put($conn_id, $upload_path . $file_name_prefix . '.' . $ext, $_FILES[$var]['tmp_name'], FTP_BINARY)) {
ftp_quit($conn_id);
return $file_name_prefix . '.' . $ext;
}
}
return '';
}
开发者ID:ivanovv,项目名称:metro4all,代码行数:17,代码来源:lib.upload.php
示例19: getHTML
function getHTML ($attr) {
if ($this->fname == '')
return '';
$ext = strtolower(file_extension($this->fname));
$appletdir = $this->dir()."/".file_strip_extension($this->fname);
$appleturl = dirname($this->url())."/".file_strip_extension($this->fname);
recursive_mkdir($appletdir);
if ($ext == 'jar' || $ext == 'zip') {
$cwd = getcwd();
chdir($appletdir);
if ($ext == 'zip')
RunTool('unzip', "IN=".$this->path(), 'pipe');
else
RunTool('unzip', "IN=".$this->path()." FILE=index.html", 'pipe');
$ok = $this->readHTMLFile('index.html');
chdir($cwd);
if (!$ok)
return '';
}
if (!isset($this->attribs['archive']))
return '';
// generate html file containing the applet
$ret = "<html><body>\n";
$ret.= '<div style="margin:0;padding:0"><applet';
foreach ($this->attribs as $k=>$v)
$ret .= " $k=\"$v\"";
$ret .= ">\n";
foreach ($this->params as $k=>$v)
$ret .= "<param name=\"$k\" value=\"$v\"/>\n";
$ret .= "</applet></div>";
$ret .= "</body></html>";
$f = fopen("$appletdir/applet.html", "w");
fputs($f, $ret);
fclose($f);
// return iframe with above applet page
$ret = "<iframe src='$appleturl/applet.html'";
$ret.= " scrolling='no' frameborder='0' marginwidth='0' marginheight='0'";
$ret.= " width='{$this->attribs['width']}' height='{$this->attribs['height']}'>\n";
$ret.= "<p>Your browser doesn't support embedded frames</p>\n";
$ret.= "</iframe>";
return $ret;
}
开发者ID:hexerei-software,项目名称:XOX-Framework,代码行数:44,代码来源:AppletObject.class.php
示例20: minifyAppendFiles
/**
* Recursieve functie die een map incl. submappen doorzoek naar *.js bestanden
*
* @return array
*/
function minifyAppendFiles(&$files, $path, $targetPrefix, $pathSuffix = '')
{
$dir = new \DirectoryIterator($path . $pathSuffix);
foreach ($dir as $entry) {
if (substr($entry->getFilename(), 0, 1) == '.') {
continue;
}
if ($entry->isDir()) {
minifyAppendFiles($files, $path, $targetPrefix, $pathSuffix . $entry->getFilename() . '/');
} else {
$extension = strtolower(file_extension($entry->getFilename()));
if (in_array($extension, array('js', 'css', 'png', 'jpeg', 'jpg'))) {
$files[$targetPrefix . substr($entry->getPathname(), strlen($path))] = $entry->getPathname();
// Add file (or overrule from app/public/)
}
}
}
return $files;
}
开发者ID:sledgehammer,项目名称:minify,代码行数:24,代码来源:minify_DocumentRoot.php
注:本文中的file_extension函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论