当前位置: 首页>>代码示例>>PHP>>正文


PHP file_extension函数代码示例

本文整理汇总了PHP中file_extension函数的典型用法代码示例。如果您正苦于以下问题:PHP file_extension函数的具体用法?PHP file_extension怎么用?PHP file_extension使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了file_extension函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的file_extension函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。