예제 #1
0
 public function openfile($filename, $filesize = null)
 {
     try {
         if (!empty($this->startup_error)) {
             throw new getid3_exception($this->startup_error);
         }
         if (!empty($this->startup_warning)) {
             $this->warning($this->startup_warning);
         }
         // init result array and set parameters
         $this->filename = $filename;
         $this->info = array();
         $this->info['GETID3_VERSION'] = $this->version();
         $this->info['php_memory_limit'] = $this->memory_limit > 0 ? $this->memory_limit : false;
         // remote files not supported
         if (preg_match('/^(ht|f)tp:\\/\\//', $filename)) {
             throw new getid3_exception('Remote files are not supported - please copy the file locally first');
         }
         $filename = str_replace('/', DIRECTORY_SEPARATOR, $filename);
         $filename = preg_replace('#(.+)' . preg_quote(DIRECTORY_SEPARATOR) . '{2,}#U', '\\1' . DIRECTORY_SEPARATOR, $filename);
         // open local file
         //if (is_readable($filename) && is_file($filename) && ($this->fp = fopen($filename, 'rb'))) { // see http://www.getid3.org/phpBB3/viewtopic.php?t=1720
         if ((is_readable($filename) || file_exists($filename)) && is_file($filename) && ($this->fp = fopen($filename, 'rb'))) {
             // great
         } else {
             $errormessagelist = array();
             if (!is_readable($filename)) {
                 $errormessagelist[] = '!is_readable';
             }
             if (!is_file($filename)) {
                 $errormessagelist[] = '!is_file';
             }
             if (!file_exists($filename)) {
                 $errormessagelist[] = '!file_exists';
             }
             if (empty($errormessagelist)) {
                 $errormessagelist[] = 'fopen failed';
             }
             throw new getid3_exception('Could not open "' . $filename . '" (' . implode('; ', $errormessagelist) . ')');
         }
         $this->info['filesize'] = !is_null($filesize) ? $filesize : filesize($filename);
         // set redundant parameters - might be needed in some include file
         // filenames / filepaths in getID3 are always expressed with forward slashes (unix-style) for both Windows and other to try and minimize confusion
         $filename = str_replace('\\', '/', $filename);
         $this->info['filepath'] = str_replace('\\', '/', realpath(dirname($filename)));
         $this->info['filename'] = getid3_lib::mb_basename($filename);
         $this->info['filenamepath'] = $this->info['filepath'] . '/' . $this->info['filename'];
         // option_max_2gb_check
         if ($this->option_max_2gb_check) {
             // PHP (32-bit all, and 64-bit Windows) doesn't support integers larger than 2^31 (~2GB)
             // filesize() simply returns (filesize % (pow(2, 32)), no matter the actual filesize
             // ftell() returns 0 if seeking to the end is beyond the range of unsigned integer
             $fseek = fseek($this->fp, 0, SEEK_END);
             if ($fseek < 0 || $this->info['filesize'] != 0 && ftell($this->fp) == 0 || $this->info['filesize'] < 0 || ftell($this->fp) < 0) {
                 $real_filesize = getid3_lib::getFileSizeSyscall($this->info['filenamepath']);
                 if ($real_filesize === false) {
                     unset($this->info['filesize']);
                     fclose($this->fp);
                     throw new getid3_exception('Unable to determine actual filesize. File is most likely larger than ' . round(PHP_INT_MAX / 1073741824) . 'GB and is not supported by PHP.');
                 } elseif (getid3_lib::intValueSupported($real_filesize)) {
                     unset($this->info['filesize']);
                     fclose($this->fp);
                     throw new getid3_exception('PHP seems to think the file is larger than ' . round(PHP_INT_MAX / 1073741824) . 'GB, but filesystem reports it as ' . number_format($real_filesize, 3) . 'GB, please report to info@getid3.org');
                 }
                 $this->info['filesize'] = $real_filesize;
                 $this->warning('File is larger than ' . round(PHP_INT_MAX / 1073741824) . 'GB (filesystem reports it as ' . number_format($real_filesize, 3) . 'GB) and is not properly supported by PHP.');
             }
         }
         // set more parameters
         $this->info['avdataoffset'] = 0;
         $this->info['avdataend'] = $this->info['filesize'];
         $this->info['fileformat'] = '';
         // filled in later
         $this->info['audio']['dataformat'] = '';
         // filled in later, unset if not used
         $this->info['video']['dataformat'] = '';
         // filled in later, unset if not used
         $this->info['tags'] = array();
         // filled in later, unset if not used
         $this->info['error'] = array();
         // filled in later, unset if not used
         $this->info['warning'] = array();
         // filled in later, unset if not used
         $this->info['comments'] = array();
         // filled in later, unset if not used
         $this->info['encoding'] = $this->encoding;
         // required by id3v2 and iso modules - can be unset at the end if desired
         return true;
     } catch (Exception $e) {
         $this->error($e->getMessage());
     }
     return false;
 }