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


PHP finfo_file函数代码示例

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


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

示例1: download

 public function download($nombre)
 {
     $path = PATH_FILES . $nombre;
     $type = '';
     if (is_file($path)) {
         $size = filesize($path);
         if (function_exists('mime_content_type')) {
             $type = mime_content_type($path);
         } else {
             if (function_exists('finfo_file')) {
                 $info = finfo_open(FILEINFO_MIME);
                 $type = finfo_file($info, $path);
                 finfo_close($info);
             }
         }
         if ($type == '') {
             $type = "application/force-download";
         }
         header("Content-Type: {$type}");
         header("Content-Disposition: attachment; filename={$nombre}");
         header("Content-Transfer-Encoding: binary");
         header("Content-Length: " . $size);
         readfile($path);
     } else {
         die("El archivo no existe.");
     }
 }
开发者ID:efaby,项目名称:postulacion,代码行数:27,代码来源:File.php

示例2: registerStaticDirectory

 /**
  * Registers all the files of a static directory as resources.
  *
  * @param string 	$path 		The absolute path on the server which contains the files
  * @param string 	$prefix 	A prefix to add to the name of the static files
  * @return Route
  */
 public function registerStaticDirectory($path)
 {
     $path = rtrim($path, '/\\');
     return $this->register('/{file}', 'get')->pattern('file', '([^\\.]{2,}.*|.)')->name($path)->before(function (&$file, &$isRightResource) use($path) {
         $file = $path . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $file);
         if (!file_exists($file) || is_dir($file)) {
             $isRightResource = false;
             return;
         }
     })->before(function ($file, $etagResponseFilter) {
         $etagResponseFilter->setEtag(md5($file . filemtime($file)));
     })->handler(function ($file, $response, $elapsedTime) {
         if (!extension_loaded('fileinfo')) {
             throw new \LogicException('The "fileinfo" extension must be activated');
         }
         $finfo = finfo_open(FILEINFO_MIME);
         $mime = finfo_file($finfo, $file);
         finfo_close($finfo);
         $pathinfo = pathinfo($file);
         if ($pathinfo['extension'] == 'css') {
             $mime = 'text/css';
         }
         if ($pathinfo['extension'] == 'js') {
             $mime = 'application/javascript';
         }
         if ($pathinfo['extension'] == 'svg') {
             $mime = 'image/svg+xml';
         }
         if (substr($mime, 0, 15) == 'application/xml' && ($pathinfo['extension'] == 'htm' || $pathinfo['extension'] == 'html')) {
             $mime = 'application/xhtml+xml';
         }
         $response->setHeader('Content-Type', $mime);
         $response->appendData(file_get_contents($file));
     });
 }
开发者ID:tomaka17,项目名称:niysu,代码行数:42,代码来源:RoutesCollection.php

示例3: mime_type

 function mime_type($file_path)
 {
     $finfo = finfo_open(FILEINFO_MIME_TYPE);
     $mime_type = finfo_file($finfo, $file_path);
     finfo_close($finfo);
     return $mime_type;
 }
开发者ID:zachborboa,项目名称:php-curl-class,代码行数:7,代码来源:Helper.php

示例4: downloadAction

 public function downloadAction()
 {
     try {
         $fileName = 'problematic_file.pdf';
         $filePath = '/ginosi/uploads/product/documents/553/2015_1421387867_Hollywood_Boulevard_Studio_Insurance_Contract_719.pdf';
         $fhandle = finfo_open(FILEINFO_MIME);
         $mime_type = finfo_file($fhandle, $filePath);
         header('Content-Type: ' . $mime_type);
         //header("Content-Length: " . filesize($filePath));
         header('Content-Disposition: attachment; filename="' . $fileName . '"');
         header('Content-Transfer-Encoding: binary');
         header('Cache-Control: no-cache');
         header('Accept-Ranges: bytes');
         // expence file download way
         //            if (file_exists($filePath)) {
         //                readfile($filePath);
         //                return true;
         //            }
         // apartment docs file download way
         echo file_get_contents($filePath, true);
         return;
     } catch (\Exception $ex) {
         echo $ex->getMessage();
     }
 }
开发者ID:arbi,项目名称:MyCode,代码行数:25,代码来源:CloudFlareController.php

示例5: getContentType

 /**
  * @return string
  */
 public function getContentType()
 {
     if (is_null($this->content_type)) {
         $this->content_type = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $this->getFullPath());
     }
     return $this->content_type;
 }
开发者ID:vojtabiberle,项目名称:MediaStorage,代码行数:10,代码来源:File.php

示例6: __construct

 function __construct($interface, $files_directory)
 {
     $field = filter_input(INPUT_POST, 'field', FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES);
     // Check for file upload.
     if ($field === NULL || empty($_FILES) || !isset($_FILES['file'])) {
         return;
     }
     $this->interface = $interface;
     // Create a new result object.
     $this->result = new stdClass();
     // Set directory.
     $this->files_directory = $files_directory;
     // Create the temporary directory if it doesn't exist.
     $dirs = array('', '/files', '/images', '/videos', '/audios');
     foreach ($dirs as $dir) {
         if (!H5PCore::dirReady($this->files_directory . $dir)) {
             $this->result->error = $this->interface->t('Unable to create directory.');
             return;
         }
     }
     // Get the field.
     $this->field = json_decode($field);
     if (function_exists('finfo_file')) {
         $finfo = finfo_open(FILEINFO_MIME_TYPE);
         $this->type = finfo_file($finfo, $_FILES['file']['tmp_name']);
         finfo_close($finfo);
     } elseif (function_exists('mime_content_type')) {
         // Deprecated, only when finfo isn't available.
         $this->type = mime_content_type($_FILES['file']['tmp_name']);
     } else {
         $this->type = $_FILES['file']['type'];
     }
     $this->extension = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
     $this->size = $_FILES['file']['size'];
 }
开发者ID:xyulex,项目名称:h5p-editor-php-library,代码行数:35,代码来源:h5peditor-file.class.php

示例7: getMIME

 function getMIME($fname)
 {
     $finfo = finfo_open(FILEINFO_MIME_TYPE);
     $mime = finfo_file($finfo, $fname);
     finfo_close($finfo);
     return $mime;
 }
开发者ID:edwardshe,项目名称:sublite-1,代码行数:7,代码来源:S3Controller.php

示例8: getType

 public function getType()
 {
     $finfo = finfo_open(FILEINFO_MIME_TYPE);
     $type = finfo_file($finfo, $this->getFullPath());
     finfo_close($finfo);
     return $type;
 }
开发者ID:moiseh,项目名称:codegen,代码行数:7,代码来源:File.php

示例9: file_mime_type

/**
 *
 * @copyright  2010-2015 izend.org
 * @version    7
 * @link       http://www.izend.org
 */
function file_mime_type($file, $encoding = true)
{
    $mime = false;
    if (function_exists('finfo_file')) {
        $finfo = finfo_open(FILEINFO_MIME);
        $mime = @finfo_file($finfo, $file);
        finfo_close($finfo);
    } else {
        if (substr(PHP_OS, 0, 3) == 'WIN') {
            $mime = mime_content_type($file);
        } else {
            $file = escapeshellarg($file);
            $cmd = "file -iL {$file}";
            exec($cmd, $output, $r);
            if ($r == 0) {
                $mime = substr($output[0], strpos($output[0], ': ') + 2);
            }
        }
    }
    if (!$mime) {
        return false;
    }
    if ($encoding) {
        return $mime;
    }
    return substr($mime, 0, strpos($mime, '; '));
}
开发者ID:RazorMarx,项目名称:izend,代码行数:33,代码来源:filemimetype.php

示例10: mime_content_type

 function mime_content_type($filename)
 {
     $finfo = finfo_open(FILEINFO_MIME);
     $mimetype = finfo_file($finfo, $filename);
     finfo_close($finfo);
     return $mimetype;
 }
开发者ID:Rudi9719,项目名称:lucid,代码行数:7,代码来源:fs.php

示例11: getUploadedFile

function getUploadedFile($name)
{
    $tmp_name = $_FILES[$name]['tmp_name'];
    $info = finfo_open(FILEINFO_MIME_TYPE);
    $mime_type = finfo_file($info, $tmp_name);
    finfo_close($info);
    $extension = '';
    switch ($mime_type) {
        case 'image/jpeg':
            $extension = 'jpg';
            break;
        case 'image/gif':
            $extension = 'gif';
            break;
        case 'image/png':
            $extension = 'png';
            break;
        default:
            $extension = '';
    }
    if ($extension != '') {
        $image_name = pathinfo($_FILES[$name]['name'])['filename'] . '.' . $extension;
        $image_file = 'img-uploads/' . $image_name;
        try {
            move_uploaded_file($tmp_name, $image_file);
        } catch (Exception $e) {
            print_r($e);
        }
    }
    return $image_name;
}
开发者ID:koyach,项目名称:dalite,代码行数:31,代码来源:media-upload.ajax.php

示例12: load

 /**
  * Loads an image from a file path
  *
  * @param string $filename Full path to the file which will be manipulated
  * @return ImageGD
  */
 public function load($filename)
 {
     if (function_exists("finfo_open")) {
         // not supported everywhere https://github.com/openphoto/frontend/issues/368
         $finfo = finfo_open(FILEINFO_MIME_TYPE);
         $this->type = finfo_file($finfo, $filename);
     } else {
         if (function_exists("mime_content_type")) {
             $this->type = mime_content_type($filename);
         } else {
             if (function_exists('exec')) {
                 $this->type = exec('/usr/bin/file --mime-type -b ' . escapeshellarg($filename));
                 if (!empty($this->type)) {
                     $this->type = "";
                 }
             }
         }
     }
     if (preg_match('/png$/', $this->type)) {
         $this->image = imagecreatefrompng($filename);
     } elseif (preg_match('/gif$/', $this->type)) {
         $this->image = @imagecreatefromgif($filename);
     } else {
         $this->image = @imagecreatefromjpeg($filename);
     }
     if (!$this->image) {
         OPException::raise(new OPInvalidImageException('Could not create image with GD library'));
     }
     $this->width = imagesx($this->image);
     $this->height = imagesy($this->image);
     return $this;
 }
开发者ID:nicolargo,项目名称:frontend,代码行数:38,代码来源:ImageGD.php

示例13: analyse

 /**
  * @param string $file
  * @return FileAnalysisResult
  */
 public static function analyse($file)
 {
     //check if file exists
     if (false === file_exists($file)) {
         return null;
     }
     //is not a file
     if (false === is_file($file)) {
         return null;
     }
     //get file size
     $size = filesize($file);
     $mimeType = null;
     //mime type getter
     if (function_exists('finfo_open')) {
         $finfo = finfo_open(FILEINFO_MIME_TYPE);
         $mimeType = finfo_file($finfo, $file);
     } else {
         if (function_exists('mime_content_type')) {
             $mimeType = mime_content_type($file);
         }
     }
     //default mime type
     if (strlen($mimeType) == 0) {
         //default mime type
         $mimeType = 'application/octet-stream';
     }
     return new FileAnalysisResult($mimeType, $size, $file);
 }
开发者ID:rugk,项目名称:threema-msgapi-sdk-php,代码行数:33,代码来源:FileAnalysisTool.php

示例14: getMimeType

 /**
  * Detects the MIME type of a given file
  * @param string $fileName The full path to the name whose MIME type you want to find out
  * @return string The MIME type, e.g. image/jpeg
  */
 static function getMimeType($fileName)
 {
     $mime = null;
     // Try fileinfo first
     if (function_exists('finfo_open')) {
         $finfo = finfo_open(FILEINFO_MIME);
         if ($finfo !== false) {
             $mime = finfo_file($finfo, $fileName);
             finfo_close($finfo);
         }
     }
     // Fallback to mime_content_type() if finfo didn't work
     if (is_null($mime) && function_exists('mime_content_type')) {
         $mime = mime_content_type($fileName);
     }
     // Final fallback, detection based on extension
     if (is_null($mime)) {
         $extension = self::getTypeIcon(getTypeIcon);
         if (array_key_exists($extension, self::$mimeMap)) {
             $mime = self::$mimeMap[$extension];
         } else {
             $mime = "application/octet-stream";
         }
     }
     return $mime;
 }
开发者ID:jlleblanc,项目名称:joomla-media-manager,代码行数:31,代码来源:media.php

示例15: detect

 /**
  * @param $file
  * @param null $filename
  * @return mixed|string
  * @throws \Exception
  */
 public static function detect($file, $filename = null)
 {
     if (!file_exists($file)) {
         throw new \Exception("File " . $file . " doesn't exist");
     }
     if (!$filename) {
         $filename = basename($file);
     }
     // check for an extension mapping first
     if ($filename) {
         $extension = \Pimcore\File::getFileExtension($filename);
         if (array_key_exists($extension, self::$extensionMapping)) {
             return self::$extensionMapping[$extension];
         }
     }
     // check with fileinfo, if there's no extension mapping
     $finfo = finfo_open(FILEINFO_MIME);
     $type = finfo_file($finfo, $file);
     finfo_close($finfo);
     if ($type !== false && !empty($type)) {
         if (strstr($type, ';')) {
             $type = substr($type, 0, strpos($type, ';'));
         }
         return $type;
     }
     // return default mime-type if we're unable to detect it
     return "application/octet-stream";
 }
开发者ID:sfie,项目名称:pimcore,代码行数:34,代码来源:Mime.php


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