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


PHP finfo_open函数代码示例

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


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

示例1: 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

示例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: 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

示例5: 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

示例6: 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

示例7: check

 /**
  * Check file mime type
  * @access	public
  * @param 	string $name
  * @param 	string $path
  * @param 	string $type
  * @return 	bool
  */
 public function check($name, $path)
 {
     $extension = strtolower(substr($name, strrpos($name, '.') + 1));
     if (function_exists('finfo_open')) {
         if ($finfo = @finfo_open(FILEINFO_MIME_TYPE)) {
             if ($mimetype = @finfo_file($finfo, $path)) {
                 @finfo_close($finfo);
                 $mime = self::getMime($mimetype);
                 if ($mime) {
                     return in_array($extension, $mime);
                 }
             }
         }
     } else {
         if (function_exists('mime_content_type')) {
             if ($mimetype = @mime_content_type($path)) {
                 $mime = self::getMime($mimetype);
                 if ($mime) {
                     return in_array($extension, $mime);
                 }
             }
         }
     }
     // server doesn't support mime type check, let it through...
     return true;
 }
开发者ID:DanyCan,项目名称:wisten.github.io,代码行数:34,代码来源:mime.php

示例8: fInstance

 /**
  * @return resource
  */
 public static function fInstance()
 {
     if (null === self::$fInstance) {
         return finfo_open(FILEINFO_MIME);
     }
     return self::$fInstance;
 }
开发者ID:judimator,项目名称:simple-search-bundle,代码行数:10,代码来源:FileIterator.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: fileMimeType

 private function fileMimeType($filePath)
 {
     $finfo = finfo_open(FILEINFO_MIME_TYPE);
     $type = finfo_file($finfo, $filePath);
     finfo_close($finfo);
     return $type;
 }
开发者ID:simnom,项目名称:Europeana-Professional,代码行数:7,代码来源:Extension.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: 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

示例13: 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

示例14: 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

示例15: forceDownload

function forceDownload($file)
{
    //Check file exist or not
    if (file_exists($file)) {
        if (ini_get('zlib.output_compression')) {
            // required for IE
            ini_set('zlib.output_compression', 'Off');
        }
        // Get mine type of file.
        $finfo = finfo_open(FILEINFO_MIME_TYPE);
        // return mime type ala mimetype extension
        $mimeType = finfo_file($finfo, $file) . "\n";
        finfo_close($finfo);
        header('Expires: 0');
        header('Pragma: public');
        header('Cache-Control: private', false);
        header('Content-Type:' . $mimeType);
        header('Content-Disposition: attachment; filename="' . basename($file) . '"');
        header('Content-Transfer-Encoding: binary');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Content-Length: ' . filesize($file));
        header('Connection: close');
        readfile($file);
        exit;
    } else {
        return "File does not exist";
    }
}
开发者ID:hiiamrohit,项目名称:force-download-php,代码行数:28,代码来源:index.php


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