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


PHP finfo::buffer方法代码示例

本文整理汇总了PHP中finfo::buffer方法的典型用法代码示例。如果您正苦于以下问题:PHP finfo::buffer方法的具体用法?PHP finfo::buffer怎么用?PHP finfo::buffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在finfo的用法示例。


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

示例1: magicMimeType

 /**
  * Tries to determine the file type magically
  * @param string $data
  * @returns a string,   the mime type, or null if none was found.
  */
 public static function magicMimeType($data)
 {
     if (self::$finfo == null) {
         if (!class_exists('finfo')) {
             I2CE::raiseError('Magic file utilties not enabled.  Please run \'pecl install Fileinfo\' or some such thing.');
             return null;
         }
         $config = I2CE::getConfig();
         $magic_file = null;
         if ($config->setIfIsSet($magic_file, "/modules/MimeTypes/magic_file")) {
             $magic_file = I2CE::getFileSearch()->search('MIME', $magic_file);
             if (!$magic_file) {
                 $magic_file == null;
             }
         }
         //I2CE::raiseError("Using $magic_file");
         //@self::$finfo = new finfo(FILEINFO_MIME, $magic_file);
         @(self::$finfo = new finfo(FILEINFO_MIME));
         if (!self::$finfo) {
             I2CE::raiseError('Unable to load magic file database ' . $magic_file, E_USER_NOTICE);
             return null;
         }
     }
     if (!($mime_type = self::$finfo->buffer($data))) {
         I2CE::raiseError('Unable to determine mime type magically', E_USER_NOTICE);
         //some error occured
         return null;
     }
     return $mime_type;
 }
开发者ID:apelon-ohie,项目名称:ihris-site,代码行数:35,代码来源:I2CE_MimeTypes.php

示例2: cache

 /**
  * Pasa el archivo cache
  * @param string $ubicacion
  * @param string $nombre
  * @return string hash del cache
  */
 public function cache($ubicacion, $nombre = null, $bo_file = true)
 {
     $this->_hash = null;
     $cache = $this->_ci->cache->iniciar();
     while (is_null($this->_hash)) {
         $this->_hash = $this->_ci->random->rand_string(20) . time();
         if ($existe = $cache->load($this->_hash)) {
             $this->_hash = null;
         }
     }
     if (is_null($nombre)) {
         $nombre = basename($ubicacion);
     }
     if ($bo_file) {
         $archivo = file_get_contents($ubicacion);
         $mime = mime_content_type($ubicacion);
         $tipo = pathinfo($ubicacion, PATHINFO_EXTENSION);
     } else {
         $archivo = $ubicacion;
         $finfo = new finfo(FILEINFO_MIME);
         $mime = $finfo->buffer($ubicacion);
         $explode = explode(".", $nombre);
         $tipo = strtolower($explode[count($explode) - 1]);
     }
     $cache->save(array("archivo" => $archivo, "archivo_nombre" => $nombre, "mime" => $mime, "tipo" => $tipo), $this->_hash);
     return $this->_hash;
 }
开发者ID:CarlosAyala,项目名称:midas-codeigniter-modulo-emergencias,代码行数:33,代码来源:Archivo_cache.php

示例3: addFile

 public function addFile($field_name, $absolute_filename_path)
 {
     $file_info = new \finfo(FILEINFO_MIME);
     $mime_type = $file_info->buffer(file_get_contents($absolute_filename_path));
     $mime = explode(';', $mime_type);
     $this->files[$field_name] = curl_file_create($absolute_filename_path, reset($mime), basename($absolute_filename_path));
 }
开发者ID:dekmabot,项目名称:lib-telegram-api,代码行数:7,代码来源:Transport.php

示例4: executeShow

 /**
  * Executes index action
  *
  * @param sfWebRequest $request A request object
  */
 public function executeShow(sfWebRequest $request)
 {
     // for apiKey check
     $memberId = $this->getUser()->getMember();
     $reqFileName = $request->getParameter('filename');
     $separates = explode('.', $reqFileName);
     $cnt = count($separates);
     $fileId = '';
     $ext = '';
     if (1 == $cnt) {
         $fileId = $reqFileName;
     } else {
         $fileId = join('', array_slice($separates, 0, $cnt - 1));
         $ext = '.' . $separates[$cnt - 1];
     }
     $file = Doctrine::getTable('File')->find($fileId);
     $this->forward404Unless($file);
     $filebin = $file->getFileBin();
     $data = $filebin->getBin();
     $filename = $file->getName();
     if (!$data) {
         return $this->renderJSON(array('status' => 'error', 'message' => 'file download error'));
     }
     $filename = substr($filename, strpos($filename, "/", 1));
     $finfo = new finfo(FILEINFO_MIME_TYPE);
     $type = $finfo->buffer($data);
     $this->getResponse()->setHttpHeader('Content-Type', $type);
     $this->getResponse()->setHttpHeader('Content-Length', strlen($data));
     // for ie
     if (1 === preg_match('/MSIE/', $request->getHttpHeader('User-Agent'))) {
         $filename = mb_convert_encoding($filename, 'sjis-win', 'utf8');
     }
     $this->getResponse()->setHttpHeader('Content-Disposition', 'attachment; filename="' . $filename . '"');
     return $this->renderText($data);
 }
开发者ID:nishizoe,项目名称:opUploadFilePlugin,代码行数:40,代码来源:actions.class.php

示例5: preSaveImageBox

 public function preSaveImageBox($field, $request)
 {
     $fieldName = $field['name'];
     if (empty($_FILES[$fieldName]['name'])) {
         if (empty($field['required'])) {
             unset($_REQUEST[$fieldName]);
         } else {
             //Settaggio necessario nel caso il campo sia not null
             $_REQUEST[$fieldName] = null;
         }
         return;
     }
     if (array_key_exists('max-dimension', $field) && !empty($field['max-dimension'])) {
         $dimension = explode(',', $field['max-dimension']);
         HelperImage::resize($_FILES[$fieldName]['tmp_name'], $dimension[0], $dimension[1]);
     }
     //Se è necessario immagazzinare il file in un blob recupero il file e lo inserisco in $_REQUEST
     if (!empty($field['store-in-blob'])) {
         $_REQUEST[$fieldName] = file_get_contents($_FILES[$fieldName]['tmp_name']);
         $_REQUEST[$fieldName . '_nam'] = $_FILES[$fieldName]['name'];
         $finfo = new \finfo(FILEINFO_MIME_TYPE);
         $_REQUEST[$fieldName . '_typ'] = $finfo->buffer($_REQUEST[$fieldName]);
         $_REQUEST[$fieldName . '_dim'] = strlen($_REQUEST[$fieldName]);
         return;
     }
     //Inserisco in $_REQUEST il filepath e sposto il file temporaneo nella directory definitiva
     $_REQUEST[$fieldName] = HelperImage::getUniqueFileName(UPLOAD_PATH . $_FILES[$fieldName]['name']);
     move_uploaded_file($_FILES[$fieldName]['tmp_name'], $_REQUEST[$fieldName]);
 }
开发者ID:spinit,项目名称:osy,代码行数:29,代码来源:HelperModel.php

示例6: getImageType

function getImageType($image_binary)
{
    $data = base64_decode($image_binary);
    $finfo = new finfo(FILEINFO_MIME_TYPE);
    $type = $finfo->buffer($data);
    return $type;
}
开发者ID:renvieir,项目名称:emprestae,代码行数:7,代码来源:handle_image.php

示例7: scale

 /**
  * Renders a scaled version of the image referenced by the provided filename, taken any (optional) manipulators into consideration.
  * @param   String  $sourceData     The binary data of the original source image.
  * @param   Array   $scaleParams
  * @param   Int     $imageType      One of the PHP image type constants, such as IMAGETYPE_JPEG
  * @return  Array
  *                  ['resource']    The image file data string
  *                  ['mime']        Mime type of the generated cache file
  *                  ['timestamp']   Timestamp of the generated cache file
  **/
 public function scale($sourceData, $scaleParams, $imageType)
 {
     $this->_setInputParams($scaleParams);
     $mem = new Garp_Util_Memory();
     $mem->useHighMemory();
     if (strlen($sourceData) == 0) {
         throw new Exception("This is an empty file!");
     }
     if (!($source = imagecreatefromstring($sourceData))) {
         $finfo = new finfo(FILEINFO_MIME);
         $mime = $finfo->buffer($sourceData);
         throw new Exception("This source image could not be scaled. It's probably not a valid file type. Instead, this file is of the following type: " . $mime);
     }
     $this->_analyzeSourceImage($source, $imageType);
     $this->_addOmittedCanvasDimension();
     if ($this->_isFilterDefined($scaleParams)) {
         Garp_Image_Filter::filter($source, $scaleParams['filter']);
     }
     if ($this->_isSourceEqualToTarget($scaleParams)) {
         $outputImage = $sourceData;
     } else {
         $canvas = $this->_createCanvasImage($imageType);
         $this->_projectSourceOnCanvas($source, $canvas);
         // Enable progressive jpegs
         imageinterlace($canvas, true);
         $outputImage = $this->_renderToImageData($canvas);
         imagedestroy($canvas);
     }
     $output = array('resource' => $outputImage, 'mime' => $this->params['mime'], 'timestamp' => time());
     imagedestroy($source);
     return $output;
 }
开发者ID:grrr-amsterdam,项目名称:garp3,代码行数:42,代码来源:Scaler.php

示例8: createFileFromPath

 public function createFileFromPath($path, $description, Google_ParentReference $fileParent = null)
 {
     $fi = new finfo(FILEINFO_MIME);
     $mimeType = explode(';', $fi->buffer(file_get_contents($path)));
     $fileName = preg_replace('/.*\\//', '', $path);
     return $this->createFile($fileName, $mimeType[0], $description, file_get_contents($path), $fileParent);
 }
开发者ID:vongalpha,项目名称:cp2google,代码行数:7,代码来源:cp2google.php

示例9: isPngData

 public function isPngData($data)
 {
     $finfo = new finfo(FILEINFO_MIME);
     $mime = $finfo->buffer($data);
     $containsPngMime = strpos($mime, 'image/png') !== false;
     return $containsPngMime;
 }
开发者ID:grrr-amsterdam,项目名称:garp3,代码行数:7,代码来源:PngQuant.php

示例10: get_mime_type

 /**
  * @param $file_loc
  * @return bool
  *
  * https://www.owasp.org/index.php/PHP_Security_Cheat_Sheet#File_uploads
  *
  *
  *
  */
 public static function get_mime_type($file_loc)
 {
     $finfo = new finfo(FILEINFO_MIME_TYPE);
     $fileContents = file_get_contents($file_loc);
     $mimeType = $finfo->buffer($fileContents);
     return $mimeType;
 }
开发者ID:Kostiantin,项目名称:joel_test_job,代码行数:16,代码来源:InputValidation.php

示例11: getMimetype

 /**
  * Determine the mimetype of the blob.
  *
  * @return string A mimetype
  */
 public function getMimetype()
 {
     if (null === $this->mimetype) {
         $finfo = new \finfo(FILEINFO_MIME);
         $this->mimetype = $finfo->buffer($this->getContent());
     }
     return $this->mimetype;
 }
开发者ID:beubi,项目名称:gitlib,代码行数:13,代码来源:Blob.php

示例12: getMimeTypeForData

 /**
  * Returns the mime type for content of a string
  * @param mixed $data
  * @param string $default
  * @return string the mime type or default
  */
 public static function getMimeTypeForData($data, $default = null)
 {
     if (class_exists('finfo', false)) {
         $finfo = new finfo(FILEINFO_MIME);
         return $finfo->buffer($data);
     }
     return $default;
 }
开发者ID:philippjenni,项目名称:icinga-web,代码行数:14,代码来源:AppKitFileUtil.class.php

示例13: itShouldConvertABase64ImageIntoBinary

 /**
  * @test 
  */
 public function itShouldConvertABase64ImageIntoBinary()
 {
     $imageData64 = self::SOME_BASE64_IMAGE;
     //Using Mime Type, 'cause binary comparison is some kind of akward
     $expectedMime = self::SOME_MIME;
     $f = new \finfo(FILEINFO_MIME);
     $this->assertThat($f->buffer($this->converter->getBinaryImageData($imageData64)), $this->equalTo($expectedMime));
 }
开发者ID:robin-drexler,项目名称:scavenger-hunt-webservice,代码行数:11,代码来源:Base64Test.php

示例14: _getImageMime

 protected function _getImageMime($bytes)
 {
     $finfo = new finfo(FILEINFO_MIME);
     $mime = $finfo->buffer($bytes);
     $mime = explode(';', $mime);
     $mime = $mime[0];
     return $mime;
 }
开发者ID:grrr-amsterdam,项目名称:garp3,代码行数:8,代码来源:Image.php

示例15: testCanGenerateLongerValidWav

 public function testCanGenerateLongerValidWav()
 {
     $wav = new Wav();
     $output = $wav->setFrequency(100)->generate($this->getLoremIpsum());
     $finfo = new \finfo(FILEINFO_MIME_TYPE);
     $mime = $finfo->buffer($output);
     $this->assertSame('audio/x-wav', $mime);
 }
开发者ID:rexxars,项目名称:morse,代码行数:8,代码来源:WavTest.php


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