Ejemplo n.º 1
0
 /**
  * Returns the start point of the file as a Timecode object if available, otherwise returns null.
  *
  * @access public
  * @author Oliver Lillie
  * @param string $file_path 
  * @param boolean $read_from_cache 
  * @return mixed Returns a string 'audio' or 'video' if media is audio or video, otherwise returns null.
  */
 public function getFileType($file_path, $read_from_cache = true)
 {
     $cache_key = 'media_parser/' . md5(realpath($file_path)) . '_parsed_type';
     if ($read_from_cache === true && ($data = $this->_cacheGet($cache_key, -1)) !== -1) {
         return $data;
     }
     //          get the raw data
     $raw_data = $this->getFileRawInformation($file_path, $read_from_cache);
     //          grab the type
     $data = null;
     if (preg_match('/Stream.*:\\s+Video:\\s+.*/', $raw_data, $matches) > 0) {
         //              special check to see if the file is actually an image and not a video.
         if (strpos(Mime::get($file_path), 'image/') !== false) {
             $data = 'image';
         } elseif (strpos(Mime::get($file_path), 'audio/') !== false) {
             $data = 'audio';
         } else {
             $data = 'video';
         }
     } else {
         if (preg_match('/Stream.*:\\s+Audio:\\s+.*/', $raw_data, $matches) > 0) {
             $data = 'audio';
         } else {
             $data = null;
         }
     }
     $this->_cacheSet($cache_key, $data);
     return $data;
 }
 /**
  * Returns the start point of the file as a Timecode object if available, otherwise returns null.
  *
  * @access public
  * @author Oliver Lillie
  * @param string $file_path 
  * @param boolean $read_from_cache 
  * @return mixed Returns a string 'audio' or 'video' if media is audio or video, otherwise returns null.
  */
 public function getFileType($file_path, $read_from_cache = true)
 {
     $cache_key = 'media_prober/' . md5(realpath($file_path)) . '_parsed_type';
     if ($read_from_cache === true && ($data = $this->_cacheGet($cache_key, -1)) !== -1) {
         return $data;
     }
     //          get the raw data
     $raw_data = $this->getFileRawInformation($file_path, $read_from_cache);
     //          grab the start times from all the streams and evaluate the earliest.
     $data = null;
     if (preg_match_all('/codec_type=(audio|video)/', $raw_data, $matches) > 0) {
         $type = null;
         foreach ($matches[1] as $key => $codec_type) {
             if ($type === null || $type === 'audio') {
                 $type = $codec_type;
             }
         }
         if ($type === 'video' && strpos(Mime::get($file_path), 'image/') !== false) {
             $type = 'image';
         }
         $data = $type;
     }
     $this->_cacheSet($cache_key, $data);
     return $data;
 }
Ejemplo n.º 3
0
 public static function info($file)
 {
     $temp = [];
     $temp['name'] = self::name($file);
     $temp['path'] = realpath($file);
     $temp['size'] = self::size($file);
     $temp['mime'] = Mime::get($file);
     $temp['extension'] = self::extension($file);
     $temp['permission'] = self::permission($file);
     $temp['time']['change'] = filemtime($file);
     $temp['time']['access'] = fileatime($file);
     return $temp;
 }
Ejemplo n.º 4
0
 /**
  * Generated from @assert (array('jpg','gif','png')) [==]  array('jpg' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png').
  *
  * @covers Mime::get
  */
 public function testGet()
 {
     $this->assertEquals(array('jpg' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png'), \Mime::get(array('jpg', 'gif', 'png')));
 }