本文整理汇总了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;
}
示例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;
}
示例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));
}
示例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);
}
示例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]);
}
示例6: getImageType
function getImageType($image_binary)
{
$data = base64_decode($image_binary);
$finfo = new finfo(FILEINFO_MIME_TYPE);
$type = $finfo->buffer($data);
return $type;
}
示例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;
}
示例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);
}
示例9: isPngData
public function isPngData($data)
{
$finfo = new finfo(FILEINFO_MIME);
$mime = $finfo->buffer($data);
$containsPngMime = strpos($mime, 'image/png') !== false;
return $containsPngMime;
}
示例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;
}
示例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;
}
示例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;
}
示例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));
}
示例14: _getImageMime
protected function _getImageMime($bytes)
{
$finfo = new finfo(FILEINFO_MIME);
$mime = $finfo->buffer($bytes);
$mime = explode(';', $mime);
$mime = $mime[0];
return $mime;
}
示例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);
}