Ejemplo n.º 1
0
 /**
  * Init image from uploaded file
  * @param $imageData
  * @return Binary
  */
 private function createBinary($imageData)
 {
     $f = finfo_open();
     $mimeType = finfo_buffer($f, $imageData, FILEINFO_MIME_TYPE);
     $binary = new Binary($imageData, $mimeType, $this->extensionGuesser->guess($mimeType));
     return $binary;
 }
Ejemplo n.º 2
0
 public static function isBinary($path)
 {
     if (false === is_readable($path)) {
         Exception::raise($path . ' is not readable', 2);
     }
     $size = filesize($path);
     if ($size < 2) {
         return false;
     }
     $data = file_get_contents($path, false, null, -1, 5012);
     if (false && function_exists('finfo_open')) {
         $finfo = finfo_open(FILEINFO_MIME_ENCODING);
         $encode = finfo_buffer($finfo, $data, FILEINFO_MIME_ENCODING);
         finfo_close($finfo);
         $data = null;
         return $encode === 'binary';
     }
     $buffer = '';
     for ($i = 0; $i < $size; ++$i) {
         if (isset($data[$i])) {
             $buffer .= sprintf('%08b', ord($data[$i]));
         }
     }
     $data = null;
     return preg_match('#^[0-1]+$#', $buffer) === 1;
 }
Ejemplo n.º 3
0
 /**
  * Returns the MIME-type of content in string
  * @param string $content
  * @return string Content mime-type
  */
 public static function getContentMimeType($content)
 {
     $finfo = finfo_open(FILEINFO_MIME_TYPE);
     $mimeType = finfo_buffer($finfo, $content);
     finfo_close($finfo);
     return $mimeType;
 }
Ejemplo n.º 4
0
 public function make()
 {
     $mime = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $this->ivatar->encode);
     $length = strlen($this->ivatar->encode);
     $response = \Response::make($this->ivatar->encode);
     $response->header('Content-Type', $mime);
     $response->header('Content-Length', $length);
     return $response;
 }
 /**
  * Bootstrap the application events.
  *
  * @return void
  */
 public function boot()
 {
     $this->package('intervention/image');
     // try to create imagecache route only if imagecache is present
     if (class_exists('Intervention\\Image\\ImageCache')) {
         $app = $this->app;
         // load imagecache config
         $app['config']->package('intervention/imagecache', __DIR__ . '/../../../../imagecache/src/config', 'imagecache');
         $config = $app['config'];
         // create dynamic manipulation route
         if (is_string($config->get('imagecache::route'))) {
             // add original to route templates
             $config->set('imagecache::templates.original', null);
             // setup image manipulator route
             $app['router']->get($config->get('imagecache::route') . '/{template}/{filename}', array('as' => 'imagecache', function ($template, $filename) use($app, $config) {
                 // disable session cookies for image route
                 $app['config']->set('session.driver', 'array');
                 // find file
                 foreach ($config->get('imagecache::paths') as $path) {
                     // don't allow '..' in filenames
                     $image_path = $path . '/' . str_replace('..', '', $filename);
                     if (file_exists($image_path) && is_file($image_path)) {
                         break;
                     } else {
                         $image_path = false;
                     }
                 }
                 // abort if file not found
                 if ($image_path === false) {
                     $app->abort(404);
                 }
                 // define template callback
                 $callback = $config->get("imagecache::templates.{$template}");
                 if (is_callable($callback) || class_exists($callback)) {
                     // image manipulation based on callback
                     $content = $app['image']->cache(function ($image) use($image_path, $callback) {
                         switch (true) {
                             case is_callable($callback):
                                 return $callback($image->make($image_path));
                                 break;
                             case class_exists($callback):
                                 return $image->make($image_path)->filter(new $callback());
                                 break;
                         }
                     }, $config->get('imagecache::lifetime'));
                 } else {
                     // get original image file contents
                     $content = file_get_contents($image_path);
                 }
                 // define mime type
                 $mime = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $content);
                 // return http response
                 return new IlluminateResponse($content, 200, array('Content-Type' => $mime, 'Cache-Control' => 'max-age=' . $config->get('imagecache::lifetime') * 60 . ', public', 'Etag' => md5($content)));
             }))->where(array('template' => join('|', array_keys($config->get('imagecache::templates'))), 'filename' => '[ \\w\\.\\/\\-]+'));
         }
     }
 }
Ejemplo n.º 6
0
function getFileType($image_data)
{
    $f = finfo_open();
    $mime_type = finfo_buffer($f, $image_data, FILEINFO_MIME_TYPE);
    $ext = get_extension($mime_type);
    if ($ext === false) {
        error("Unsupported filetype: " . $mime_type);
    }
    return $ext;
}
Ejemplo n.º 7
0
 /**
  * Initiates new image from binary data
  *
  * @param  string $data
  * @return \Intervention\Image\Image
  */
 public function initFromBinary($binary)
 {
     $resource = @imagecreatefromstring($binary);
     if ($resource === false) {
         throw new \Intervention\Image\Exception\NotReadableException("Unable to init from given binary data.");
     }
     $image = $this->initFromGdResource($resource);
     $image->mime = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $binary);
     return $image;
 }
Ejemplo n.º 8
0
 /**
  * Get the mime encoding (e.g. "binary" or "us-ascii" or "utf-8") of the file.
  *
  * @return string
  */
 public function getMIMEEncoding()
 {
     $adapter = $this->file->internalPathname()->localAdapter();
     if ($adapter instanceof MimeAwareAdapterInterface) {
         return $adapter->getMimeEncoding($this->file->internalPathname());
     }
     return Util::executeFunction(function () {
         return finfo_buffer(Util::getFileInfo(), $this->file->getContents(), FILEINFO_MIME_ENCODING);
     }, 'Filicious\\Exception\\PluginException', 0, 'Could not determine mime encoding');
 }
Ejemplo n.º 9
0
 public function get($filename)
 {
     $path = config('images.path') . $filename;
     if (!Storage::exists($path)) {
         throw new ImageNotFoundHttpException();
     }
     $data = Storage::get($path);
     $mime = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $data);
     return Response::make($data)->header('Content-Type', $mime)->header('Content-Length', strlen($data));
 }
Ejemplo n.º 10
0
 /**
  * Builds PSR7 compatible response. May replace "response" command in
  * some future.
  *
  * Method will generate binary stream and put it inside PSR-7
  * ResponseInterface. Following code can be optimized using native php
  * streams and more "clean" streaming, however drivers has to be updated
  * first.
  *
  * @param  \Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $format = $this->argument(0)->value();
     $quality = $this->argument(1)->between(0, 100)->value();
     //Encoded property will be populated at this moment
     $stream = $image->stream($format, $quality);
     $mimetype = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $image->getEncoded());
     $this->setOutput(new Response(200, array('Content-Type' => $mimetype, 'Content-Length' => strlen($image->getEncoded())), $stream));
     return true;
 }
Ejemplo n.º 11
0
 /**
  * Get the file's mimetype.
  * 
  * @return string
  */
 public function getMimetype()
 {
     $finfo = finfo_open(FILEINFO_MIME_TYPE);
     $mime_type = finfo_buffer($finfo, $this->getContent());
     finfo_close($finfo);
     if (strpos($mime_type, ';') !== false) {
         list($mime_type, $info) = explode(';', $mime_type);
     }
     return trim($mime_type);
 }
 public function show($id)
 {
     $user = DB::table('tbl_admins')->where('tbl_admins.id', '=', $id)->join('cat_datos_maestros as genero', 'tbl_admins.lng_idgenero', '=', 'genero.id')->join('cat_roles', 'tbl_admins.lng_idrol', '=', 'cat_roles.id')->select('tbl_admins.id', 'tbl_admins.name', 'tbl_admins.str_cedula', 'tbl_admins.str_nombre', 'tbl_admins.str_apellido', 'genero.str_descripcion as genero', 'tbl_admins.str_telefono', 'tbl_admins.email', 'tbl_admins.created_at', 'cat_roles.str_rol', 'tbl_admins.bol_eliminado', 'tbl_admins.blb_img')->get();
     // Detectando el Tipo de Formato del la Imagen
     $a = base64_decode($user[0]->blb_img);
     $b = finfo_open();
     //Agregando un nuevo atributo al array
     $user[0]->format = finfo_buffer($b, $a, FILEINFO_MIME_TYPE);
     //return $persona;
     return view('admin.show', ['user' => $user])->with('page_title', 'Consultar');
 }
Ejemplo n.º 13
0
 /**
  * @param string $base64Data
  * @param string $prefix
  * @param string $extension
  * @param int    $width
  * @param int    $height
  *
  * @return string
  */
 public function uploadBase64($base64Data, $prefix = 'avatar/', $extension = 'jpg', $width = null, $height = null)
 {
     $data = base64_decode($base64Data);
     $resource = finfo_open();
     $mime_type = finfo_buffer($resource, $data, FILEINFO_MIME_TYPE);
     $map = array('image/gif' => 'gif', 'image/jpeg' => 'jpg', 'image/png' => 'png');
     if ($mime_type && isset($map[$mime_type])) {
         $extension = $map[$mime_type];
     }
     return $this->uploadData($data, $prefix, $extension, $width, $height);
 }
Ejemplo n.º 14
0
 public static function image_base64($url)
 {
     $image = file_get_contents($url);
     $f = finfo_open();
     $mime_type = finfo_buffer($f, $image, FILEINFO_MIME_TYPE);
     if (in_array($mime_type, array('image/png', 'image/jpeg', 'image/gif'))) {
         return "data:{$mime_type};base64," . base64_encode($image);
     } else {
         return null;
     }
 }
Ejemplo n.º 15
0
 /**
  * Detect mime type from a resource.
  *
  * @param  resource $resource
  * @return string
  */
 public function detectFromResource($resource)
 {
     $handle = $this->getHandle();
     $meta = stream_get_meta_data($resource);
     if (file_exists($meta['uri'])) {
         $type = finfo_file($handle, $meta['uri']);
     } else {
         $type = finfo_buffer($handle, fread($resource, 1000000));
     }
     return $this->fixType($type);
 }
Ejemplo n.º 16
0
 public function analyze($handle)
 {
     $meta = stream_get_meta_data($handle);
     if (file_exists($meta['uri'])) {
         $result = finfo_file($this->_resource, $meta['uri']);
     } else {
         $result = finfo_buffer($this->_resource, fread($handle, 1000000));
     }
     if ($result != 'application/x-empty') {
         return $result;
     }
 }
 public static function getMIMETypeFromContents($fileContents)
 {
     // get mime type
     $finfo = finfo_open(FILEINFO_MIME, static::$magicPath);
     if (!$finfo || !($mimeInfo = finfo_buffer($finfo, $fileContents))) {
         throw new Exception('Unable to load file info');
     }
     finfo_close($finfo);
     // split mime type
     $p = strpos($mimeInfo, ';');
     return $p ? substr($mimeInfo, 0, $p) : $mimeInfo;
 }
Ejemplo n.º 18
0
 public function process($url)
 {
     $fname = basename($url);
     $this->mediaData->originalName = strlen($fname) > 255 ? md5($fname) : $fname;
     $this->fileData = file_get_contents($url);
     // get mime using finfo.
     $finfo = finfo_open(FILEINFO_MIME_TYPE);
     $mime = finfo_buffer($finfo, $this->fileData);
     $this->mediaData->mime = $mime === FALSE ? "application/octet-stream" : $mime;
     $this->mediaData->size = strlen($this->fileData);
     return;
 }
Ejemplo n.º 19
0
 function prepareHtmlMail($html, $eol, $boundary_rel, $boundary_alt)
 {
     preg_match_all('~<img.*?src=.([\\/.a-z0-9:;,+=_-]+).*?>~si', $html, $matches);
     $i = 0;
     $paths = array();
     foreach ($matches[1] as $img) {
         $img_old = $img;
         if (strpos($img, "http://") === false) {
             $paths[$i]['img'] = $img;
             $content_id = md5($img);
             $html = str_replace($img_old, 'cid:' . $content_id, $html);
             $paths[$i++]['cid'] = $content_id;
         }
     }
     $multipart = '';
     $multipart .= "{$boundary_alt}{$eol}";
     $multipart .= "Content-Type: text/plain; charset=UTF-8{$eol}{$eol}{$eol}";
     $multipart .= "{$boundary_alt}{$eol}";
     $multipart .= "Content-Type: text/html; charset=UTF-8{$eol}{$eol}";
     $multipart .= "{$html}{$eol}{$eol}";
     $multipart .= "{$boundary_alt}--{$eol}";
     foreach ($paths as $key => $path) {
         $img_data = explode(",", $path["img"]);
         $imgdata = base64_decode($img_data[1]);
         $f = finfo_open();
         $mime_type = finfo_buffer($f, $imgdata, FILEINFO_MIME_TYPE);
         $filename = "image_{$key}";
         switch ($mime_type) {
             case "image/jpeg":
                 $filename .= ".jpg";
                 break;
             case "image/png":
                 $filename .= ".jpg";
                 break;
             case "image/gif":
                 $filename .= ".jpg";
                 break;
             default:
                 $filename .= ".jpg";
                 break;
         }
         $message_part .= "Content-Type: {$mime_type}; name=\"{$filename}\"{$eol}";
         $message_part .= "Content-Disposition: inline; filename=\"{$filename}\"{$eol}";
         $message_part .= "Content-Transfer-Encoding: base64{$eol}";
         $message_part .= "Content-ID: <{$path['cid']}>{$eol}";
         $message_part .= "X-Attachment-Id: {$path['cid']}{$eol}{$eol}";
         $message_part .= $img_data[1];
         $multipart .= "{$boundary_rel}{$eol}" . $message_part . "{$eol}";
     }
     $multipart .= "{$boundary_rel}--";
     return $multipart;
 }
Ejemplo n.º 20
0
 /**
  * Initiates new image from binary data
  *
  * @param  string $data
  * @return \Intervention\Image\Image
  */
 public function initFromBinary($binary)
 {
     $core = new \Imagick();
     try {
         $core->readImageBlob($binary);
     } catch (\ImagickException $e) {
         throw new \Intervention\Image\Exception\NotReadableException("Unable to read image from binary data.", 0, $e);
     }
     // build image
     $image = $this->initFromImagick($core);
     $image->mime = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $binary);
     return $image;
 }
Ejemplo n.º 21
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $paises = Pais::All();
     foreach ($paises as $key => $value) {
         // Detectando el Tipo de Formato del la Imagen
         $a = base64_decode($value['blb_img']);
         $b = finfo_open();
         $type = finfo_buffer($b, $a, FILEINFO_MIME_TYPE);
         // Agregando un nuevo atributo al array
         $value['format'] = $type;
     }
     return view('pais.pais', compact('paises'))->with('page_title', 'Principal');
 }
Ejemplo n.º 22
0
 /**
  * Builds response according to settings
  *
  * @return mixed
  */
 public function make()
 {
     $this->image->encode($this->format, $this->quality);
     $data = $this->image->getEncoded();
     $mime = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $data);
     if (function_exists('app') && is_a($app = app(), 'Illuminate\\Foundation\\Application')) {
         $response = \Response::make($data);
         $response->header('Content-Type', $mime);
     } else {
         header('Content-Type: ' . $mime);
         $response = $data;
     }
     return $response;
 }
Ejemplo n.º 23
0
 /**
  * Returns the MIME content type of file.
  * @param  string
  * @return string
  */
 public static function fromString($data)
 {
     if (extension_loaded('fileinfo') && preg_match('#^(\\S+/[^\\s;]+)#', finfo_buffer(finfo_open(FILEINFO_MIME), $data), $m)) {
         return $m[1];
     } elseif (strncmp($data, "��", 2) === 0) {
         return 'image/jpeg';
     } elseif (strncmp($data, "�PNG", 4) === 0) {
         return 'image/png';
     } elseif (strncmp($data, "GIF", 3) === 0) {
         return 'image/gif';
     } else {
         return 'application/octet-stream';
     }
 }
Ejemplo n.º 24
0
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     $app = $this->app;
     $app['image'] = $app->share(function ($app) {
         return new Image();
     });
     // try to create imagecache route only if imagecache is present
     if (class_exists('\\Intervention\\Image\\ImageCache')) {
         // load imagecache config
         $app['config']->package('intervention/imagecache', __DIR__ . '/../../../../imagecache/src/config');
         $config = $app['config']->get('imagecache::imagecache');
         // create dynamic manipulation route
         if (is_string($config['route'])) {
             // add original to route templates
             $config['templates']['original'] = null;
             // setup image manipulator route
             $app['router']->get($config['route'] . '/{template}/{filename}', array('as' => 'imagecache', function ($template, $filename) use($app, $config) {
                 // find file
                 foreach ($config['paths'] as $path) {
                     $image_path = $path . '/' . $filename;
                     if (file_exists($image_path) && is_file($image_path)) {
                         break;
                     } else {
                         $image_path = false;
                     }
                 }
                 // abort if file not found
                 if ($image_path === false) {
                     $app->abort(404);
                 }
                 // define template callback
                 $callback = $config['templates'][$template];
                 if (is_callable($callback)) {
                     // image manipulation based on callback
                     $content = $app['image']->cache(function ($image) use($image_path, $callback) {
                         return $callback($image->make($image_path));
                     }, $config['lifetime']);
                 } else {
                     // get original image file contents
                     $content = file_get_contents($image_path);
                 }
                 // define mime type
                 $mime = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $content);
                 // return http response
                 return new \Illuminate\Http\Response($content, 200, array('Content-Type' => $mime, 'Cache-Control' => 'max-age=' . $config['lifetime'] * 60 . ', public', 'Etag' => md5($content)));
             }))->where(array('template' => join('|', array_keys($config['templates'])), 'filename' => '^[\\/\\w.-]+$'));
         }
     }
 }
Ejemplo n.º 25
0
 /**
  * @param $buffer
  * @return string|null
  */
 protected function detectBufferMimeType($buffer)
 {
     $type = null;
     if (function_exists('finfo_open')) {
         if (static::$fileInfoDb === null) {
             ErrorHandler::start();
             static::$fileInfoDb = finfo_open(FILEINFO_MIME_TYPE);
             ErrorHandler::stop();
         }
         if (static::$fileInfoDb) {
             $type = finfo_buffer(static::$fileInfoDb, $buffer, FILEINFO_MIME_TYPE);
         }
     }
     return $type;
 }
 /**
  * Send a media stored via the UploadedFileManager
  *
  * @Config\Route("/{key}", name="open_orchestra_media_get")
  * @Config\Method({"GET"})
  *
  * @return Response
  */
 public function getAction($key)
 {
     $mediaStorageManager = $this->get('open_orchestra_media_file.manager.storage');
     $fileContent = $mediaStorageManager->getFileContent($key);
     $finfo = finfo_open(FILEINFO_MIME);
     $mimetype = finfo_buffer($finfo, $fileContent);
     finfo_close($finfo);
     $response = new Response();
     $response->headers->set('Content-Type', $mimetype);
     $response->headers->set('Content-Length', strlen($fileContent));
     $response->setContent($fileContent);
     $response->setPublic();
     $response->setMaxAge(2629743);
     return $response;
 }
Ejemplo n.º 27
0
function showdownload()
{
    global $file;
    $content = $file->content();
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");
    $finfo = finfo_open(FILEINFO_MIME);
    header('Content-type: ' . finfo_buffer($finfo, $content));
    finfo_close($finfo);
    header("Content-Disposition: attachment; filename=" . htmlentities($file->name()));
    echo $content;
    die;
}
Ejemplo n.º 28
0
 /**
  * Create Attachment instance and move file to attachmentsDirectory
  *
  * @param $data
  * @param $fileName
  * @param string $mime
  * @return \Attachment
  * @throws \Exception
  */
 protected function createAttachment($data, $fileName, $mime = '')
 {
     if (empty($mime)) {
         $f = finfo_open();
         $mime = finfo_buffer($f, $data, FILEINFO_MIME_TYPE);
     }
     $newAttachment = new \Attachment(array('filename' => $fileName, 'fileextension' => pathinfo($fileName, PATHINFO_EXTENSION), 'mimetype' => $mime, 'filesize' => strlen($data)));
     $newAttachment->save();
     $destinationFolder = \Config::get('paperwork.attachmentsDirectory') . '/' . $newAttachment->id;
     if (!\File::makeDirectory($destinationFolder, 0700)) {
         $newAttachment->delete();
         throw new \Exception('Error creating directory');
     }
     file_put_contents($destinationFolder . '/' . $fileName, $data);
     return $newAttachment;
 }
Ejemplo n.º 29
0
 /**
  * 添加文件访问入口.
  */
 private function addFileEntrance()
 {
     $domain = array_get($this->app['config'], 'alioss.domain', '');
     $this->app['router']->group($domain ? compact('domain') : [], function ($router) {
         $router->get('/{oss_bucket}/{file}', function ($bucket, $file) {
             $alioss = $this->app['filesystem.alioss'];
             $alioss->setBucket($bucket);
             @(list($key, $ext) = explode('.', $file));
             $content = file_get_contents($alioss->getUrl($key));
             $fileInfo = finfo_open(FILEINFO_MIME_TYPE);
             $mime = finfo_buffer($fileInfo, $content);
             finfo_close($fileInfo);
             return response()->data($content)->header('Content-Type', $mime);
         });
     });
 }
 function display($tpl = null)
 {
     include_once 'components/com_advancedopenportal/models/SugarCasesConnection.php';
     $user =& JFactory::getUser();
     $this->errors = array();
     $note_id = JRequest::getVar('id');
     $caseConnection = new SugarCasesConnection();
     $this->attachment = $caseConnection->getNoteAttachment($note_id);
     $finfo = finfo_open(FILEINFO_MIME_TYPE);
     $file = base64_decode($this->attachment['file']);
     $mime = finfo_buffer($finfo, $file);
     header("Content-type: " . $mime);
     header("Content-Disposition: attachment;filename=" . $this->attachment['filename']);
     echo $file;
     jexit();
 }