Edit File by line
/home/barbar84/www/wp-inclu.../ID3
File: getid3.php
<?php
[0] Fix | Delete
/////////////////////////////////////////////////////////////////
[1] Fix | Delete
/// getID3() by James Heinrich <info@getid3.org> //
[2] Fix | Delete
// available at https://github.com/JamesHeinrich/getID3 //
[3] Fix | Delete
// or https://www.getid3.org //
[4] Fix | Delete
// or http://getid3.sourceforge.net //
[5] Fix | Delete
// //
[6] Fix | Delete
// Please see readme.txt for more information //
[7] Fix | Delete
// ///
[8] Fix | Delete
/////////////////////////////////////////////////////////////////
[9] Fix | Delete
[10] Fix | Delete
// define a constant rather than looking up every time it is needed
[11] Fix | Delete
if (!defined('GETID3_OS_ISWINDOWS')) {
[12] Fix | Delete
define('GETID3_OS_ISWINDOWS', (stripos(PHP_OS, 'WIN') === 0));
[13] Fix | Delete
}
[14] Fix | Delete
// Get base path of getID3() - ONCE
[15] Fix | Delete
if (!defined('GETID3_INCLUDEPATH')) {
[16] Fix | Delete
define('GETID3_INCLUDEPATH', dirname(__FILE__).DIRECTORY_SEPARATOR);
[17] Fix | Delete
}
[18] Fix | Delete
// Workaround Bug #39923 (https://bugs.php.net/bug.php?id=39923)
[19] Fix | Delete
if (!defined('IMG_JPG') && defined('IMAGETYPE_JPEG')) {
[20] Fix | Delete
define('IMG_JPG', IMAGETYPE_JPEG);
[21] Fix | Delete
}
[22] Fix | Delete
if (!defined('ENT_SUBSTITUTE')) { // PHP5.3 adds ENT_IGNORE, PHP5.4 adds ENT_SUBSTITUTE
[23] Fix | Delete
define('ENT_SUBSTITUTE', (defined('ENT_IGNORE') ? ENT_IGNORE : 8));
[24] Fix | Delete
}
[25] Fix | Delete
[26] Fix | Delete
/*
[27] Fix | Delete
https://www.getid3.org/phpBB3/viewtopic.php?t=2114
[28] Fix | Delete
If you are running into a the problem where filenames with special characters are being handled
[29] Fix | Delete
incorrectly by external helper programs (e.g. metaflac), notably with the special characters removed,
[30] Fix | Delete
and you are passing in the filename in UTF8 (typically via a HTML form), try uncommenting this line:
[31] Fix | Delete
*/
[32] Fix | Delete
//setlocale(LC_CTYPE, 'en_US.UTF-8');
[33] Fix | Delete
[34] Fix | Delete
// attempt to define temp dir as something flexible but reliable
[35] Fix | Delete
$temp_dir = ini_get('upload_tmp_dir');
[36] Fix | Delete
if ($temp_dir && (!is_dir($temp_dir) || !is_readable($temp_dir))) {
[37] Fix | Delete
$temp_dir = '';
[38] Fix | Delete
}
[39] Fix | Delete
if (!$temp_dir && function_exists('sys_get_temp_dir')) { // sys_get_temp_dir added in PHP v5.2.1
[40] Fix | Delete
// sys_get_temp_dir() may give inaccessible temp dir, e.g. with open_basedir on virtual hosts
[41] Fix | Delete
$temp_dir = sys_get_temp_dir();
[42] Fix | Delete
}
[43] Fix | Delete
$temp_dir = @realpath($temp_dir); // see https://github.com/JamesHeinrich/getID3/pull/10
[44] Fix | Delete
$open_basedir = ini_get('open_basedir');
[45] Fix | Delete
if ($open_basedir) {
[46] Fix | Delete
// e.g. "/var/www/vhosts/getid3.org/httpdocs/:/tmp/"
[47] Fix | Delete
$temp_dir = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $temp_dir);
[48] Fix | Delete
$open_basedir = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $open_basedir);
[49] Fix | Delete
if (substr($temp_dir, -1, 1) != DIRECTORY_SEPARATOR) {
[50] Fix | Delete
$temp_dir .= DIRECTORY_SEPARATOR;
[51] Fix | Delete
}
[52] Fix | Delete
$found_valid_tempdir = false;
[53] Fix | Delete
$open_basedirs = explode(PATH_SEPARATOR, $open_basedir);
[54] Fix | Delete
foreach ($open_basedirs as $basedir) {
[55] Fix | Delete
if (substr($basedir, -1, 1) != DIRECTORY_SEPARATOR) {
[56] Fix | Delete
$basedir .= DIRECTORY_SEPARATOR;
[57] Fix | Delete
}
[58] Fix | Delete
if (preg_match('#^'.preg_quote($basedir).'#', $temp_dir)) {
[59] Fix | Delete
$found_valid_tempdir = true;
[60] Fix | Delete
break;
[61] Fix | Delete
}
[62] Fix | Delete
}
[63] Fix | Delete
if (!$found_valid_tempdir) {
[64] Fix | Delete
$temp_dir = '';
[65] Fix | Delete
}
[66] Fix | Delete
unset($open_basedirs, $found_valid_tempdir, $basedir);
[67] Fix | Delete
}
[68] Fix | Delete
if (!$temp_dir) {
[69] Fix | Delete
$temp_dir = '*'; // invalid directory name should force tempnam() to use system default temp dir
[70] Fix | Delete
}
[71] Fix | Delete
// $temp_dir = '/something/else/'; // feel free to override temp dir here if it works better for your system
[72] Fix | Delete
if (!defined('GETID3_TEMP_DIR')) {
[73] Fix | Delete
define('GETID3_TEMP_DIR', $temp_dir);
[74] Fix | Delete
}
[75] Fix | Delete
unset($open_basedir, $temp_dir);
[76] Fix | Delete
[77] Fix | Delete
// End: Defines
[78] Fix | Delete
[79] Fix | Delete
[80] Fix | Delete
class getID3
[81] Fix | Delete
{
[82] Fix | Delete
/*
[83] Fix | Delete
* Settings
[84] Fix | Delete
*/
[85] Fix | Delete
[86] Fix | Delete
/**
[87] Fix | Delete
* CASE SENSITIVE! - i.e. (must be supported by iconv()). Examples: ISO-8859-1 UTF-8 UTF-16 UTF-16BE
[88] Fix | Delete
*
[89] Fix | Delete
* @var string
[90] Fix | Delete
*/
[91] Fix | Delete
public $encoding = 'UTF-8';
[92] Fix | Delete
[93] Fix | Delete
/**
[94] Fix | Delete
* Should always be 'ISO-8859-1', but some tags may be written in other encodings such as 'EUC-CN' or 'CP1252'
[95] Fix | Delete
*
[96] Fix | Delete
* @var string
[97] Fix | Delete
*/
[98] Fix | Delete
public $encoding_id3v1 = 'ISO-8859-1';
[99] Fix | Delete
[100] Fix | Delete
/**
[101] Fix | Delete
* ID3v1 should always be 'ISO-8859-1', but some tags may be written in other encodings such as 'Windows-1251' or 'KOI8-R'. If true attempt to detect these encodings, but may return incorrect values for some tags actually in ISO-8859-1 encoding
[102] Fix | Delete
*
[103] Fix | Delete
* @var bool
[104] Fix | Delete
*/
[105] Fix | Delete
public $encoding_id3v1_autodetect = false;
[106] Fix | Delete
[107] Fix | Delete
/*
[108] Fix | Delete
* Optional tag checks - disable for speed.
[109] Fix | Delete
*/
[110] Fix | Delete
[111] Fix | Delete
/**
[112] Fix | Delete
* Read and process ID3v1 tags
[113] Fix | Delete
*
[114] Fix | Delete
* @var bool
[115] Fix | Delete
*/
[116] Fix | Delete
public $option_tag_id3v1 = true;
[117] Fix | Delete
[118] Fix | Delete
/**
[119] Fix | Delete
* Read and process ID3v2 tags
[120] Fix | Delete
*
[121] Fix | Delete
* @var bool
[122] Fix | Delete
*/
[123] Fix | Delete
public $option_tag_id3v2 = true;
[124] Fix | Delete
[125] Fix | Delete
/**
[126] Fix | Delete
* Read and process Lyrics3 tags
[127] Fix | Delete
*
[128] Fix | Delete
* @var bool
[129] Fix | Delete
*/
[130] Fix | Delete
public $option_tag_lyrics3 = true;
[131] Fix | Delete
[132] Fix | Delete
/**
[133] Fix | Delete
* Read and process APE tags
[134] Fix | Delete
*
[135] Fix | Delete
* @var bool
[136] Fix | Delete
*/
[137] Fix | Delete
public $option_tag_apetag = true;
[138] Fix | Delete
[139] Fix | Delete
/**
[140] Fix | Delete
* Copy tags to root key 'tags' and encode to $this->encoding
[141] Fix | Delete
*
[142] Fix | Delete
* @var bool
[143] Fix | Delete
*/
[144] Fix | Delete
public $option_tags_process = true;
[145] Fix | Delete
[146] Fix | Delete
/**
[147] Fix | Delete
* Copy tags to root key 'tags_html' properly translated from various encodings to HTML entities
[148] Fix | Delete
*
[149] Fix | Delete
* @var bool
[150] Fix | Delete
*/
[151] Fix | Delete
public $option_tags_html = true;
[152] Fix | Delete
[153] Fix | Delete
/*
[154] Fix | Delete
* Optional tag/comment calculations
[155] Fix | Delete
*/
[156] Fix | Delete
[157] Fix | Delete
/**
[158] Fix | Delete
* Calculate additional info such as bitrate, channelmode etc
[159] Fix | Delete
*
[160] Fix | Delete
* @var bool
[161] Fix | Delete
*/
[162] Fix | Delete
public $option_extra_info = true;
[163] Fix | Delete
[164] Fix | Delete
/*
[165] Fix | Delete
* Optional handling of embedded attachments (e.g. images)
[166] Fix | Delete
*/
[167] Fix | Delete
[168] Fix | Delete
/**
[169] Fix | Delete
* Defaults to true (ATTACHMENTS_INLINE) for backward compatibility
[170] Fix | Delete
*
[171] Fix | Delete
* @var bool|string
[172] Fix | Delete
*/
[173] Fix | Delete
public $option_save_attachments = true;
[174] Fix | Delete
[175] Fix | Delete
/*
[176] Fix | Delete
* Optional calculations
[177] Fix | Delete
*/
[178] Fix | Delete
[179] Fix | Delete
/**
[180] Fix | Delete
* Get MD5 sum of data part - slow
[181] Fix | Delete
*
[182] Fix | Delete
* @var bool
[183] Fix | Delete
*/
[184] Fix | Delete
public $option_md5_data = false;
[185] Fix | Delete
[186] Fix | Delete
/**
[187] Fix | Delete
* Use MD5 of source file if availble - only FLAC and OptimFROG
[188] Fix | Delete
*
[189] Fix | Delete
* @var bool
[190] Fix | Delete
*/
[191] Fix | Delete
public $option_md5_data_source = false;
[192] Fix | Delete
[193] Fix | Delete
/**
[194] Fix | Delete
* Get SHA1 sum of data part - slow
[195] Fix | Delete
*
[196] Fix | Delete
* @var bool
[197] Fix | Delete
*/
[198] Fix | Delete
public $option_sha1_data = false;
[199] Fix | Delete
[200] Fix | Delete
/**
[201] Fix | Delete
* Check whether file is larger than 2GB and thus not supported by 32-bit PHP (null: auto-detect based on
[202] Fix | Delete
* PHP_INT_MAX)
[203] Fix | Delete
*
[204] Fix | Delete
* @var bool|null
[205] Fix | Delete
*/
[206] Fix | Delete
public $option_max_2gb_check;
[207] Fix | Delete
[208] Fix | Delete
/**
[209] Fix | Delete
* Read buffer size in bytes
[210] Fix | Delete
*
[211] Fix | Delete
* @var int
[212] Fix | Delete
*/
[213] Fix | Delete
public $option_fread_buffer_size = 32768;
[214] Fix | Delete
[215] Fix | Delete
// Public variables
[216] Fix | Delete
[217] Fix | Delete
/**
[218] Fix | Delete
* Filename of file being analysed.
[219] Fix | Delete
*
[220] Fix | Delete
* @var string
[221] Fix | Delete
*/
[222] Fix | Delete
public $filename;
[223] Fix | Delete
[224] Fix | Delete
/**
[225] Fix | Delete
* Filepointer to file being analysed.
[226] Fix | Delete
*
[227] Fix | Delete
* @var resource
[228] Fix | Delete
*/
[229] Fix | Delete
public $fp;
[230] Fix | Delete
[231] Fix | Delete
/**
[232] Fix | Delete
* Result array.
[233] Fix | Delete
*
[234] Fix | Delete
* @var array
[235] Fix | Delete
*/
[236] Fix | Delete
public $info;
[237] Fix | Delete
[238] Fix | Delete
/**
[239] Fix | Delete
* @var string
[240] Fix | Delete
*/
[241] Fix | Delete
public $tempdir = GETID3_TEMP_DIR;
[242] Fix | Delete
[243] Fix | Delete
/**
[244] Fix | Delete
* @var int
[245] Fix | Delete
*/
[246] Fix | Delete
public $memory_limit = 0;
[247] Fix | Delete
[248] Fix | Delete
/**
[249] Fix | Delete
* @var string
[250] Fix | Delete
*/
[251] Fix | Delete
protected $startup_error = '';
[252] Fix | Delete
[253] Fix | Delete
/**
[254] Fix | Delete
* @var string
[255] Fix | Delete
*/
[256] Fix | Delete
protected $startup_warning = '';
[257] Fix | Delete
[258] Fix | Delete
const VERSION = '1.9.20-202006061653';
[259] Fix | Delete
const FREAD_BUFFER_SIZE = 32768;
[260] Fix | Delete
[261] Fix | Delete
const ATTACHMENTS_NONE = false;
[262] Fix | Delete
const ATTACHMENTS_INLINE = true;
[263] Fix | Delete
[264] Fix | Delete
public function __construct() {
[265] Fix | Delete
[266] Fix | Delete
// Check for PHP version
[267] Fix | Delete
$required_php_version = '5.3.0';
[268] Fix | Delete
if (version_compare(PHP_VERSION, $required_php_version, '<')) {
[269] Fix | Delete
$this->startup_error .= 'getID3() requires PHP v'.$required_php_version.' or higher - you are running v'.PHP_VERSION."\n";
[270] Fix | Delete
return;
[271] Fix | Delete
}
[272] Fix | Delete
[273] Fix | Delete
// Check memory
[274] Fix | Delete
$memoryLimit = ini_get('memory_limit');
[275] Fix | Delete
if (preg_match('#([0-9]+) ?M#i', $memoryLimit, $matches)) {
[276] Fix | Delete
// could be stored as "16M" rather than 16777216 for example
[277] Fix | Delete
$memoryLimit = $matches[1] * 1048576;
[278] Fix | Delete
} elseif (preg_match('#([0-9]+) ?G#i', $memoryLimit, $matches)) { // The 'G' modifier is available since PHP 5.1.0
[279] Fix | Delete
// could be stored as "2G" rather than 2147483648 for example
[280] Fix | Delete
$memoryLimit = $matches[1] * 1073741824;
[281] Fix | Delete
}
[282] Fix | Delete
$this->memory_limit = $memoryLimit;
[283] Fix | Delete
[284] Fix | Delete
if ($this->memory_limit <= 0) {
[285] Fix | Delete
// memory limits probably disabled
[286] Fix | Delete
} elseif ($this->memory_limit <= 4194304) {
[287] Fix | Delete
$this->startup_error .= 'PHP has less than 4MB available memory and will very likely run out. Increase memory_limit in php.ini'."\n";
[288] Fix | Delete
} elseif ($this->memory_limit <= 12582912) {
[289] Fix | Delete
$this->startup_warning .= 'PHP has less than 12MB available memory and might run out if all modules are loaded. Increase memory_limit in php.ini'."\n";
[290] Fix | Delete
}
[291] Fix | Delete
[292] Fix | Delete
// Check safe_mode off
[293] Fix | Delete
if (preg_match('#(1|ON)#i', ini_get('safe_mode'))) { // phpcs:ignore PHPCompatibility.IniDirectives.RemovedIniDirectives.safe_modeDeprecatedRemoved
[294] Fix | Delete
$this->warning('WARNING: Safe mode is on, shorten support disabled, md5data/sha1data for ogg vorbis disabled, ogg vorbos/flac tag writing disabled.');
[295] Fix | Delete
}
[296] Fix | Delete
[297] Fix | Delete
// phpcs:ignore PHPCompatibility.IniDirectives.RemovedIniDirectives.mbstring_func_overloadDeprecated
[298] Fix | Delete
if (($mbstring_func_overload = (int) ini_get('mbstring.func_overload')) && ($mbstring_func_overload & 0x02)) {
[299] Fix | Delete
// http://php.net/manual/en/mbstring.overload.php
[300] Fix | Delete
// "mbstring.func_overload in php.ini is a positive value that represents a combination of bitmasks specifying the categories of functions to be overloaded. It should be set to 1 to overload the mail() function. 2 for string functions, 4 for regular expression functions"
[301] Fix | Delete
// getID3 cannot run when string functions are overloaded. It doesn't matter if mail() or ereg* functions are overloaded since getID3 does not use those.
[302] Fix | Delete
// phpcs:ignore PHPCompatibility.IniDirectives.RemovedIniDirectives.mbstring_func_overloadDeprecated
[303] Fix | Delete
$this->startup_error .= 'WARNING: php.ini contains "mbstring.func_overload = '.ini_get('mbstring.func_overload').'", getID3 cannot run with this setting (bitmask 2 (string functions) cannot be set). Recommended to disable entirely.'."\n";
[304] Fix | Delete
}
[305] Fix | Delete
[306] Fix | Delete
// check for magic quotes in PHP < 7.4.0 (when these functions became deprecated)
[307] Fix | Delete
if (version_compare(PHP_VERSION, '7.4.0', '<')) {
[308] Fix | Delete
// Check for magic_quotes_runtime
[309] Fix | Delete
if (function_exists('get_magic_quotes_runtime')) {
[310] Fix | Delete
// phpcs:ignore PHPCompatibility.FunctionUse.RemovedFunctions.get_magic_quotes_runtimeDeprecated
[311] Fix | Delete
if (get_magic_quotes_runtime()) {
[312] Fix | Delete
$this->startup_error .= 'magic_quotes_runtime must be disabled before running getID3(). Surround getid3 block by set_magic_quotes_runtime(0) and set_magic_quotes_runtime(1).'."\n";
[313] Fix | Delete
}
[314] Fix | Delete
}
[315] Fix | Delete
// Check for magic_quotes_gpc
[316] Fix | Delete
if (function_exists('get_magic_quotes_gpc')) {
[317] Fix | Delete
// phpcs:ignore PHPCompatibility.FunctionUse.RemovedFunctions.get_magic_quotes_gpcDeprecated
[318] Fix | Delete
if (get_magic_quotes_gpc()) {
[319] Fix | Delete
$this->startup_error .= 'magic_quotes_gpc must be disabled before running getID3(). Surround getid3 block by set_magic_quotes_gpc(0) and set_magic_quotes_gpc(1).'."\n";
[320] Fix | Delete
}
[321] Fix | Delete
}
[322] Fix | Delete
}
[323] Fix | Delete
[324] Fix | Delete
// Load support library
[325] Fix | Delete
if (!include_once(GETID3_INCLUDEPATH.'getid3.lib.php')) {
[326] Fix | Delete
$this->startup_error .= 'getid3.lib.php is missing or corrupt'."\n";
[327] Fix | Delete
}
[328] Fix | Delete
[329] Fix | Delete
if ($this->option_max_2gb_check === null) {
[330] Fix | Delete
$this->option_max_2gb_check = (PHP_INT_MAX <= 2147483647);
[331] Fix | Delete
}
[332] Fix | Delete
[333] Fix | Delete
[334] Fix | Delete
// Needed for Windows only:
[335] Fix | Delete
// Define locations of helper applications for Shorten, VorbisComment, MetaFLAC
[336] Fix | Delete
// as well as other helper functions such as head, etc
[337] Fix | Delete
// This path cannot contain spaces, but the below code will attempt to get the
[338] Fix | Delete
// 8.3-equivalent path automatically
[339] Fix | Delete
// IMPORTANT: This path must include the trailing slash
[340] Fix | Delete
if (GETID3_OS_ISWINDOWS && !defined('GETID3_HELPERAPPSDIR')) {
[341] Fix | Delete
[342] Fix | Delete
$helperappsdir = GETID3_INCLUDEPATH.'..'.DIRECTORY_SEPARATOR.'helperapps'; // must not have any space in this path
[343] Fix | Delete
[344] Fix | Delete
if (!is_dir($helperappsdir)) {
[345] Fix | Delete
$this->startup_warning .= '"'.$helperappsdir.'" cannot be defined as GETID3_HELPERAPPSDIR because it does not exist'."\n";
[346] Fix | Delete
} elseif (strpos(realpath($helperappsdir), ' ') !== false) {
[347] Fix | Delete
$DirPieces = explode(DIRECTORY_SEPARATOR, realpath($helperappsdir));
[348] Fix | Delete
$path_so_far = array();
[349] Fix | Delete
foreach ($DirPieces as $key => $value) {
[350] Fix | Delete
if (strpos($value, ' ') !== false) {
[351] Fix | Delete
if (!empty($path_so_far)) {
[352] Fix | Delete
$commandline = 'dir /x '.escapeshellarg(implode(DIRECTORY_SEPARATOR, $path_so_far));
[353] Fix | Delete
$dir_listing = `$commandline`;
[354] Fix | Delete
$lines = explode("\n", $dir_listing);
[355] Fix | Delete
foreach ($lines as $line) {
[356] Fix | Delete
$line = trim($line);
[357] Fix | Delete
if (preg_match('#^([0-9/]{10}) +([0-9:]{4,5}( [AP]M)?) +(<DIR>|[0-9,]+) +([^ ]{0,11}) +(.+)$#', $line, $matches)) {
[358] Fix | Delete
list($dummy, $date, $time, $ampm, $filesize, $shortname, $filename) = $matches;
[359] Fix | Delete
if ((strtoupper($filesize) == '<DIR>') && (strtolower($filename) == strtolower($value))) {
[360] Fix | Delete
$value = $shortname;
[361] Fix | Delete
}
[362] Fix | Delete
}
[363] Fix | Delete
}
[364] Fix | Delete
} else {
[365] Fix | Delete
$this->startup_warning .= 'GETID3_HELPERAPPSDIR must not have any spaces in it - use 8dot3 naming convention if neccesary. You can run "dir /x" from the commandline to see the correct 8.3-style names.'."\n";
[366] Fix | Delete
}
[367] Fix | Delete
}
[368] Fix | Delete
$path_so_far[] = $value;
[369] Fix | Delete
}
[370] Fix | Delete
$helperappsdir = implode(DIRECTORY_SEPARATOR, $path_so_far);
[371] Fix | Delete
}
[372] Fix | Delete
define('GETID3_HELPERAPPSDIR', $helperappsdir.DIRECTORY_SEPARATOR);
[373] Fix | Delete
}
[374] Fix | Delete
[375] Fix | Delete
if (!empty($this->startup_error)) {
[376] Fix | Delete
echo $this->startup_error;
[377] Fix | Delete
throw new getid3_exception($this->startup_error);
[378] Fix | Delete
}
[379] Fix | Delete
}
[380] Fix | Delete
[381] Fix | Delete
/**
[382] Fix | Delete
* @return string
[383] Fix | Delete
*/
[384] Fix | Delete
public function version() {
[385] Fix | Delete
return self::VERSION;
[386] Fix | Delete
}
[387] Fix | Delete
[388] Fix | Delete
/**
[389] Fix | Delete
* @return int
[390] Fix | Delete
*/
[391] Fix | Delete
public function fread_buffer_size() {
[392] Fix | Delete
return $this->option_fread_buffer_size;
[393] Fix | Delete
}
[394] Fix | Delete
[395] Fix | Delete
/**
[396] Fix | Delete
* @param array $optArray
[397] Fix | Delete
*
[398] Fix | Delete
* @return bool
[399] Fix | Delete
*/
[400] Fix | Delete
public function setOption($optArray) {
[401] Fix | Delete
if (!is_array($optArray) || empty($optArray)) {
[402] Fix | Delete
return false;
[403] Fix | Delete
}
[404] Fix | Delete
foreach ($optArray as $opt => $val) {
[405] Fix | Delete
if (isset($this->$opt) === false) {
[406] Fix | Delete
continue;
[407] Fix | Delete
}
[408] Fix | Delete
$this->$opt = $val;
[409] Fix | Delete
}
[410] Fix | Delete
return true;
[411] Fix | Delete
}
[412] Fix | Delete
[413] Fix | Delete
/**
[414] Fix | Delete
* @param string $filename
[415] Fix | Delete
* @param int $filesize
[416] Fix | Delete
* @param resource $fp
[417] Fix | Delete
*
[418] Fix | Delete
* @return bool
[419] Fix | Delete
*
[420] Fix | Delete
* @throws getid3_exception
[421] Fix | Delete
*/
[422] Fix | Delete
public function openfile($filename, $filesize=null, $fp=null) {
[423] Fix | Delete
try {
[424] Fix | Delete
if (!empty($this->startup_error)) {
[425] Fix | Delete
throw new getid3_exception($this->startup_error);
[426] Fix | Delete
}
[427] Fix | Delete
if (!empty($this->startup_warning)) {
[428] Fix | Delete
foreach (explode("\n", $this->startup_warning) as $startup_warning) {
[429] Fix | Delete
$this->warning($startup_warning);
[430] Fix | Delete
}
[431] Fix | Delete
}
[432] Fix | Delete
[433] Fix | Delete
// init result array and set parameters
[434] Fix | Delete
$this->filename = $filename;
[435] Fix | Delete
$this->info = array();
[436] Fix | Delete
$this->info['GETID3_VERSION'] = $this->version();
[437] Fix | Delete
$this->info['php_memory_limit'] = (($this->memory_limit > 0) ? $this->memory_limit : false);
[438] Fix | Delete
[439] Fix | Delete
// remote files not supported
[440] Fix | Delete
if (preg_match('#^(ht|f)tp://#', $filename)) {
[441] Fix | Delete
throw new getid3_exception('Remote files are not supported - please copy the file locally first');
[442] Fix | Delete
}
[443] Fix | Delete
[444] Fix | Delete
$filename = str_replace('/', DIRECTORY_SEPARATOR, $filename);
[445] Fix | Delete
//$filename = preg_replace('#(?<!gs:)('.preg_quote(DIRECTORY_SEPARATOR).'{2,})#', DIRECTORY_SEPARATOR, $filename);
[446] Fix | Delete
[447] Fix | Delete
// open local file
[448] Fix | Delete
//if (is_readable($filename) && is_file($filename) && ($this->fp = fopen($filename, 'rb'))) { // see https://www.getid3.org/phpBB3/viewtopic.php?t=1720
[449] Fix | Delete
if (($fp != null) && ((get_resource_type($fp) == 'file') || (get_resource_type($fp) == 'stream'))) {
[450] Fix | Delete
$this->fp = $fp;
[451] Fix | Delete
} elseif ((is_readable($filename) || file_exists($filename)) && is_file($filename) && ($this->fp = fopen($filename, 'rb'))) {
[452] Fix | Delete
// great
[453] Fix | Delete
} else {
[454] Fix | Delete
$errormessagelist = array();
[455] Fix | Delete
if (!is_readable($filename)) {
[456] Fix | Delete
$errormessagelist[] = '!is_readable';
[457] Fix | Delete
}
[458] Fix | Delete
if (!is_file($filename)) {
[459] Fix | Delete
$errormessagelist[] = '!is_file';
[460] Fix | Delete
}
[461] Fix | Delete
if (!file_exists($filename)) {
[462] Fix | Delete
$errormessagelist[] = '!file_exists';
[463] Fix | Delete
}
[464] Fix | Delete
if (empty($errormessagelist)) {
[465] Fix | Delete
$errormessagelist[] = 'fopen failed';
[466] Fix | Delete
}
[467] Fix | Delete
throw new getid3_exception('Could not open "'.$filename.'" ('.implode('; ', $errormessagelist).')');
[468] Fix | Delete
}
[469] Fix | Delete
[470] Fix | Delete
$this->info['filesize'] = (!is_null($filesize) ? $filesize : filesize($filename));
[471] Fix | Delete
// set redundant parameters - might be needed in some include file
[472] Fix | Delete
// filenames / filepaths in getID3 are always expressed with forward slashes (unix-style) for both Windows and other to try and minimize confusion
[473] Fix | Delete
$filename = str_replace('\\', '/', $filename);
[474] Fix | Delete
$this->info['filepath'] = str_replace('\\', '/', realpath(dirname($filename)));
[475] Fix | Delete
$this->info['filename'] = getid3_lib::mb_basename($filename);
[476] Fix | Delete
$this->info['filenamepath'] = $this->info['filepath'].'/'.$this->info['filename'];
[477] Fix | Delete
[478] Fix | Delete
// set more parameters
[479] Fix | Delete
$this->info['avdataoffset'] = 0;
[480] Fix | Delete
$this->info['avdataend'] = $this->info['filesize'];
[481] Fix | Delete
$this->info['fileformat'] = ''; // filled in later
[482] Fix | Delete
$this->info['audio']['dataformat'] = ''; // filled in later, unset if not used
[483] Fix | Delete
$this->info['video']['dataformat'] = ''; // filled in later, unset if not used
[484] Fix | Delete
$this->info['tags'] = array(); // filled in later, unset if not used
[485] Fix | Delete
$this->info['error'] = array(); // filled in later, unset if not used
[486] Fix | Delete
$this->info['warning'] = array(); // filled in later, unset if not used
[487] Fix | Delete
$this->info['comments'] = array(); // filled in later, unset if not used
[488] Fix | Delete
$this->info['encoding'] = $this->encoding; // required by id3v2 and iso modules - can be unset at the end if desired
[489] Fix | Delete
[490] Fix | Delete
// option_max_2gb_check
[491] Fix | Delete
if ($this->option_max_2gb_check) {
[492] Fix | Delete
// PHP (32-bit all, and 64-bit Windows) doesn't support integers larger than 2^31 (~2GB)
[493] Fix | Delete
// filesize() simply returns (filesize % (pow(2, 32)), no matter the actual filesize
[494] Fix | Delete
// ftell() returns 0 if seeking to the end is beyond the range of unsigned integer
[495] Fix | Delete
$fseek = fseek($this->fp, 0, SEEK_END);
[496] Fix | Delete
if (($fseek < 0) || (($this->info['filesize'] != 0) && (ftell($this->fp) == 0)) ||
[497] Fix | Delete
($this->info['filesize'] < 0) ||
[498] Fix | Delete
(ftell($this->fp) < 0)) {
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function