Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../httpdocs/clone/wp-inclu.../ID3
File: getid3.php
*/
[2000] Fix | Delete
public function CalculateCompressionRatioAudio() {
[2001] Fix | Delete
if (empty($this->info['audio']['bitrate']) || empty($this->info['audio']['channels']) || empty($this->info['audio']['sample_rate']) || !is_numeric($this->info['audio']['sample_rate'])) {
[2002] Fix | Delete
return false;
[2003] Fix | Delete
}
[2004] Fix | Delete
$this->info['audio']['compression_ratio'] = $this->info['audio']['bitrate'] / ($this->info['audio']['channels'] * $this->info['audio']['sample_rate'] * (!empty($this->info['audio']['bits_per_sample']) ? $this->info['audio']['bits_per_sample'] : 16));
[2005] Fix | Delete
[2006] Fix | Delete
if (!empty($this->info['audio']['streams'])) {
[2007] Fix | Delete
foreach ($this->info['audio']['streams'] as $streamnumber => $streamdata) {
[2008] Fix | Delete
if (!empty($streamdata['bitrate']) && !empty($streamdata['channels']) && !empty($streamdata['sample_rate'])) {
[2009] Fix | Delete
$this->info['audio']['streams'][$streamnumber]['compression_ratio'] = $streamdata['bitrate'] / ($streamdata['channels'] * $streamdata['sample_rate'] * (!empty($streamdata['bits_per_sample']) ? $streamdata['bits_per_sample'] : 16));
[2010] Fix | Delete
}
[2011] Fix | Delete
}
[2012] Fix | Delete
}
[2013] Fix | Delete
return true;
[2014] Fix | Delete
}
[2015] Fix | Delete
[2016] Fix | Delete
/**
[2017] Fix | Delete
* @return bool
[2018] Fix | Delete
*/
[2019] Fix | Delete
public function CalculateReplayGain() {
[2020] Fix | Delete
if (isset($this->info['replay_gain'])) {
[2021] Fix | Delete
if (!isset($this->info['replay_gain']['reference_volume'])) {
[2022] Fix | Delete
$this->info['replay_gain']['reference_volume'] = 89.0;
[2023] Fix | Delete
}
[2024] Fix | Delete
if (isset($this->info['replay_gain']['track']['adjustment'])) {
[2025] Fix | Delete
$this->info['replay_gain']['track']['volume'] = $this->info['replay_gain']['reference_volume'] - $this->info['replay_gain']['track']['adjustment'];
[2026] Fix | Delete
}
[2027] Fix | Delete
if (isset($this->info['replay_gain']['album']['adjustment'])) {
[2028] Fix | Delete
$this->info['replay_gain']['album']['volume'] = $this->info['replay_gain']['reference_volume'] - $this->info['replay_gain']['album']['adjustment'];
[2029] Fix | Delete
}
[2030] Fix | Delete
[2031] Fix | Delete
if (isset($this->info['replay_gain']['track']['peak'])) {
[2032] Fix | Delete
$this->info['replay_gain']['track']['max_noclip_gain'] = 0 - getid3_lib::RGADamplitude2dB($this->info['replay_gain']['track']['peak']);
[2033] Fix | Delete
}
[2034] Fix | Delete
if (isset($this->info['replay_gain']['album']['peak'])) {
[2035] Fix | Delete
$this->info['replay_gain']['album']['max_noclip_gain'] = 0 - getid3_lib::RGADamplitude2dB($this->info['replay_gain']['album']['peak']);
[2036] Fix | Delete
}
[2037] Fix | Delete
}
[2038] Fix | Delete
return true;
[2039] Fix | Delete
}
[2040] Fix | Delete
[2041] Fix | Delete
/**
[2042] Fix | Delete
* @return bool
[2043] Fix | Delete
*/
[2044] Fix | Delete
public function ProcessAudioStreams() {
[2045] Fix | Delete
if (!empty($this->info['audio']['bitrate']) || !empty($this->info['audio']['channels']) || !empty($this->info['audio']['sample_rate'])) {
[2046] Fix | Delete
if (!isset($this->info['audio']['streams'])) {
[2047] Fix | Delete
foreach ($this->info['audio'] as $key => $value) {
[2048] Fix | Delete
if ($key != 'streams') {
[2049] Fix | Delete
$this->info['audio']['streams'][0][$key] = $value;
[2050] Fix | Delete
}
[2051] Fix | Delete
}
[2052] Fix | Delete
}
[2053] Fix | Delete
}
[2054] Fix | Delete
return true;
[2055] Fix | Delete
}
[2056] Fix | Delete
[2057] Fix | Delete
/**
[2058] Fix | Delete
* @return string|bool
[2059] Fix | Delete
*/
[2060] Fix | Delete
public function getid3_tempnam() {
[2061] Fix | Delete
return tempnam($this->tempdir, 'gI3');
[2062] Fix | Delete
}
[2063] Fix | Delete
[2064] Fix | Delete
/**
[2065] Fix | Delete
* @param string $name
[2066] Fix | Delete
*
[2067] Fix | Delete
* @return bool
[2068] Fix | Delete
*
[2069] Fix | Delete
* @throws getid3_exception
[2070] Fix | Delete
*/
[2071] Fix | Delete
public function include_module($name) {
[2072] Fix | Delete
//if (!file_exists($this->include_path.'module.'.$name.'.php')) {
[2073] Fix | Delete
if (!file_exists(GETID3_INCLUDEPATH.'module.'.$name.'.php')) {
[2074] Fix | Delete
throw new getid3_exception('Required module.'.$name.'.php is missing.');
[2075] Fix | Delete
}
[2076] Fix | Delete
include_once(GETID3_INCLUDEPATH.'module.'.$name.'.php');
[2077] Fix | Delete
return true;
[2078] Fix | Delete
}
[2079] Fix | Delete
[2080] Fix | Delete
/**
[2081] Fix | Delete
* @param string $filename
[2082] Fix | Delete
*
[2083] Fix | Delete
* @return bool
[2084] Fix | Delete
*/
[2085] Fix | Delete
public static function is_writable ($filename) {
[2086] Fix | Delete
$ret = is_writable($filename);
[2087] Fix | Delete
if (!$ret) {
[2088] Fix | Delete
$perms = fileperms($filename);
[2089] Fix | Delete
$ret = ($perms & 0x0080) || ($perms & 0x0010) || ($perms & 0x0002);
[2090] Fix | Delete
}
[2091] Fix | Delete
return $ret;
[2092] Fix | Delete
}
[2093] Fix | Delete
[2094] Fix | Delete
}
[2095] Fix | Delete
[2096] Fix | Delete
[2097] Fix | Delete
abstract class getid3_handler
[2098] Fix | Delete
{
[2099] Fix | Delete
[2100] Fix | Delete
/**
[2101] Fix | Delete
* @var getID3
[2102] Fix | Delete
*/
[2103] Fix | Delete
protected $getid3; // pointer
[2104] Fix | Delete
[2105] Fix | Delete
/**
[2106] Fix | Delete
* Analyzing filepointer or string.
[2107] Fix | Delete
*
[2108] Fix | Delete
* @var bool
[2109] Fix | Delete
*/
[2110] Fix | Delete
protected $data_string_flag = false;
[2111] Fix | Delete
[2112] Fix | Delete
/**
[2113] Fix | Delete
* String to analyze.
[2114] Fix | Delete
*
[2115] Fix | Delete
* @var string
[2116] Fix | Delete
*/
[2117] Fix | Delete
protected $data_string = '';
[2118] Fix | Delete
[2119] Fix | Delete
/**
[2120] Fix | Delete
* Seek position in string.
[2121] Fix | Delete
*
[2122] Fix | Delete
* @var int
[2123] Fix | Delete
*/
[2124] Fix | Delete
protected $data_string_position = 0;
[2125] Fix | Delete
[2126] Fix | Delete
/**
[2127] Fix | Delete
* String length.
[2128] Fix | Delete
*
[2129] Fix | Delete
* @var int
[2130] Fix | Delete
*/
[2131] Fix | Delete
protected $data_string_length = 0;
[2132] Fix | Delete
[2133] Fix | Delete
/**
[2134] Fix | Delete
* @var string
[2135] Fix | Delete
*/
[2136] Fix | Delete
private $dependency_to;
[2137] Fix | Delete
[2138] Fix | Delete
/**
[2139] Fix | Delete
* getid3_handler constructor.
[2140] Fix | Delete
*
[2141] Fix | Delete
* @param getID3 $getid3
[2142] Fix | Delete
* @param string $call_module
[2143] Fix | Delete
*/
[2144] Fix | Delete
public function __construct(getID3 $getid3, $call_module=null) {
[2145] Fix | Delete
$this->getid3 = $getid3;
[2146] Fix | Delete
[2147] Fix | Delete
if ($call_module) {
[2148] Fix | Delete
$this->dependency_to = str_replace('getid3_', '', $call_module);
[2149] Fix | Delete
}
[2150] Fix | Delete
}
[2151] Fix | Delete
[2152] Fix | Delete
/**
[2153] Fix | Delete
* Analyze from file pointer.
[2154] Fix | Delete
*
[2155] Fix | Delete
* @return bool
[2156] Fix | Delete
*/
[2157] Fix | Delete
abstract public function Analyze();
[2158] Fix | Delete
[2159] Fix | Delete
/**
[2160] Fix | Delete
* Analyze from string instead.
[2161] Fix | Delete
*
[2162] Fix | Delete
* @param string $string
[2163] Fix | Delete
*/
[2164] Fix | Delete
public function AnalyzeString($string) {
[2165] Fix | Delete
// Enter string mode
[2166] Fix | Delete
$this->setStringMode($string);
[2167] Fix | Delete
[2168] Fix | Delete
// Save info
[2169] Fix | Delete
$saved_avdataoffset = $this->getid3->info['avdataoffset'];
[2170] Fix | Delete
$saved_avdataend = $this->getid3->info['avdataend'];
[2171] Fix | Delete
$saved_filesize = (isset($this->getid3->info['filesize']) ? $this->getid3->info['filesize'] : null); // may be not set if called as dependency without openfile() call
[2172] Fix | Delete
[2173] Fix | Delete
// Reset some info
[2174] Fix | Delete
$this->getid3->info['avdataoffset'] = 0;
[2175] Fix | Delete
$this->getid3->info['avdataend'] = $this->getid3->info['filesize'] = $this->data_string_length;
[2176] Fix | Delete
[2177] Fix | Delete
// Analyze
[2178] Fix | Delete
$this->Analyze();
[2179] Fix | Delete
[2180] Fix | Delete
// Restore some info
[2181] Fix | Delete
$this->getid3->info['avdataoffset'] = $saved_avdataoffset;
[2182] Fix | Delete
$this->getid3->info['avdataend'] = $saved_avdataend;
[2183] Fix | Delete
$this->getid3->info['filesize'] = $saved_filesize;
[2184] Fix | Delete
[2185] Fix | Delete
// Exit string mode
[2186] Fix | Delete
$this->data_string_flag = false;
[2187] Fix | Delete
}
[2188] Fix | Delete
[2189] Fix | Delete
/**
[2190] Fix | Delete
* @param string $string
[2191] Fix | Delete
*/
[2192] Fix | Delete
public function setStringMode($string) {
[2193] Fix | Delete
$this->data_string_flag = true;
[2194] Fix | Delete
$this->data_string = $string;
[2195] Fix | Delete
$this->data_string_length = strlen($string);
[2196] Fix | Delete
}
[2197] Fix | Delete
[2198] Fix | Delete
/**
[2199] Fix | Delete
* @phpstan-impure
[2200] Fix | Delete
*
[2201] Fix | Delete
* @return int|bool
[2202] Fix | Delete
*/
[2203] Fix | Delete
protected function ftell() {
[2204] Fix | Delete
if ($this->data_string_flag) {
[2205] Fix | Delete
return $this->data_string_position;
[2206] Fix | Delete
}
[2207] Fix | Delete
return ftell($this->getid3->fp);
[2208] Fix | Delete
}
[2209] Fix | Delete
[2210] Fix | Delete
/**
[2211] Fix | Delete
* @param int $bytes
[2212] Fix | Delete
*
[2213] Fix | Delete
* @phpstan-impure
[2214] Fix | Delete
*
[2215] Fix | Delete
* @return string|false
[2216] Fix | Delete
*
[2217] Fix | Delete
* @throws getid3_exception
[2218] Fix | Delete
*/
[2219] Fix | Delete
protected function fread($bytes) {
[2220] Fix | Delete
if ($this->data_string_flag) {
[2221] Fix | Delete
$this->data_string_position += $bytes;
[2222] Fix | Delete
return substr($this->data_string, $this->data_string_position - $bytes, $bytes);
[2223] Fix | Delete
}
[2224] Fix | Delete
if ($bytes == 0) {
[2225] Fix | Delete
return '';
[2226] Fix | Delete
} elseif ($bytes < 0) {
[2227] Fix | Delete
throw new getid3_exception('cannot fread('.$bytes.' from '.$this->ftell().')', 10);
[2228] Fix | Delete
}
[2229] Fix | Delete
$pos = $this->ftell() + $bytes;
[2230] Fix | Delete
if (!getid3_lib::intValueSupported($pos)) {
[2231] Fix | Delete
throw new getid3_exception('cannot fread('.$bytes.' from '.$this->ftell().') because beyond PHP filesystem limit', 10);
[2232] Fix | Delete
}
[2233] Fix | Delete
[2234] Fix | Delete
//return fread($this->getid3->fp, $bytes);
[2235] Fix | Delete
/*
[2236] Fix | Delete
* https://www.getid3.org/phpBB3/viewtopic.php?t=1930
[2237] Fix | Delete
* "I found out that the root cause for the problem was how getID3 uses the PHP system function fread().
[2238] Fix | Delete
* It seems to assume that fread() would always return as many bytes as were requested.
[2239] Fix | Delete
* However, according the PHP manual (http://php.net/manual/en/function.fread.php), this is the case only with regular local files, but not e.g. with Linux pipes.
[2240] Fix | Delete
* The call may return only part of the requested data and a new call is needed to get more."
[2241] Fix | Delete
*/
[2242] Fix | Delete
$contents = '';
[2243] Fix | Delete
do {
[2244] Fix | Delete
//if (($this->getid3->memory_limit > 0) && ($bytes > $this->getid3->memory_limit)) {
[2245] Fix | Delete
if (($this->getid3->memory_limit > 0) && (($bytes / $this->getid3->memory_limit) > 0.99)) { // enable a more-fuzzy match to prevent close misses generating errors like "PHP Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 33554464 bytes)"
[2246] Fix | Delete
throw new getid3_exception('cannot fread('.$bytes.' from '.$this->ftell().') that is more than available PHP memory ('.$this->getid3->memory_limit.')', 10);
[2247] Fix | Delete
}
[2248] Fix | Delete
$part = fread($this->getid3->fp, $bytes);
[2249] Fix | Delete
$partLength = strlen($part);
[2250] Fix | Delete
$bytes -= $partLength;
[2251] Fix | Delete
$contents .= $part;
[2252] Fix | Delete
} while (($bytes > 0) && ($partLength > 0));
[2253] Fix | Delete
return $contents;
[2254] Fix | Delete
}
[2255] Fix | Delete
[2256] Fix | Delete
/**
[2257] Fix | Delete
* @param int $bytes
[2258] Fix | Delete
* @param int $whence
[2259] Fix | Delete
*
[2260] Fix | Delete
* @phpstan-impure
[2261] Fix | Delete
*
[2262] Fix | Delete
* @return int
[2263] Fix | Delete
*
[2264] Fix | Delete
* @throws getid3_exception
[2265] Fix | Delete
*/
[2266] Fix | Delete
protected function fseek($bytes, $whence=SEEK_SET) {
[2267] Fix | Delete
if ($this->data_string_flag) {
[2268] Fix | Delete
switch ($whence) {
[2269] Fix | Delete
case SEEK_SET:
[2270] Fix | Delete
$this->data_string_position = $bytes;
[2271] Fix | Delete
break;
[2272] Fix | Delete
[2273] Fix | Delete
case SEEK_CUR:
[2274] Fix | Delete
$this->data_string_position += $bytes;
[2275] Fix | Delete
break;
[2276] Fix | Delete
[2277] Fix | Delete
case SEEK_END:
[2278] Fix | Delete
$this->data_string_position = $this->data_string_length + $bytes;
[2279] Fix | Delete
break;
[2280] Fix | Delete
}
[2281] Fix | Delete
return 0; // fseek returns 0 on success
[2282] Fix | Delete
}
[2283] Fix | Delete
[2284] Fix | Delete
$pos = $bytes;
[2285] Fix | Delete
if ($whence == SEEK_CUR) {
[2286] Fix | Delete
$pos = $this->ftell() + $bytes;
[2287] Fix | Delete
} elseif ($whence == SEEK_END) {
[2288] Fix | Delete
$pos = $this->getid3->info['filesize'] + $bytes;
[2289] Fix | Delete
}
[2290] Fix | Delete
if (!getid3_lib::intValueSupported($pos)) {
[2291] Fix | Delete
throw new getid3_exception('cannot fseek('.$pos.') because beyond PHP filesystem limit', 10);
[2292] Fix | Delete
}
[2293] Fix | Delete
[2294] Fix | Delete
// https://github.com/JamesHeinrich/getID3/issues/327
[2295] Fix | Delete
$result = fseek($this->getid3->fp, $bytes, $whence);
[2296] Fix | Delete
if ($result !== 0) { // fseek returns 0 on success
[2297] Fix | Delete
throw new getid3_exception('cannot fseek('.$pos.'). resource/stream does not appear to support seeking', 10);
[2298] Fix | Delete
}
[2299] Fix | Delete
return $result;
[2300] Fix | Delete
}
[2301] Fix | Delete
[2302] Fix | Delete
/**
[2303] Fix | Delete
* @phpstan-impure
[2304] Fix | Delete
*
[2305] Fix | Delete
* @return string|false
[2306] Fix | Delete
*
[2307] Fix | Delete
* @throws getid3_exception
[2308] Fix | Delete
*/
[2309] Fix | Delete
protected function fgets() {
[2310] Fix | Delete
// must be able to handle CR/LF/CRLF but not read more than one lineend
[2311] Fix | Delete
$buffer = ''; // final string we will return
[2312] Fix | Delete
$prevchar = ''; // save previously-read character for end-of-line checking
[2313] Fix | Delete
if ($this->data_string_flag) {
[2314] Fix | Delete
while (true) {
[2315] Fix | Delete
$thischar = substr($this->data_string, $this->data_string_position++, 1);
[2316] Fix | Delete
if (($prevchar == "\r") && ($thischar != "\n")) {
[2317] Fix | Delete
// read one byte too many, back up
[2318] Fix | Delete
$this->data_string_position--;
[2319] Fix | Delete
break;
[2320] Fix | Delete
}
[2321] Fix | Delete
$buffer .= $thischar;
[2322] Fix | Delete
if ($thischar == "\n") {
[2323] Fix | Delete
break;
[2324] Fix | Delete
}
[2325] Fix | Delete
if ($this->data_string_position >= $this->data_string_length) {
[2326] Fix | Delete
// EOF
[2327] Fix | Delete
break;
[2328] Fix | Delete
}
[2329] Fix | Delete
$prevchar = $thischar;
[2330] Fix | Delete
}
[2331] Fix | Delete
[2332] Fix | Delete
} else {
[2333] Fix | Delete
[2334] Fix | Delete
// Ideally we would just use PHP's fgets() function, however...
[2335] Fix | Delete
// it does not behave consistently with regards to mixed line endings, may be system-dependent
[2336] Fix | Delete
// and breaks entirely when given a file with mixed \r vs \n vs \r\n line endings (e.g. some PDFs)
[2337] Fix | Delete
//return fgets($this->getid3->fp);
[2338] Fix | Delete
while (true) {
[2339] Fix | Delete
$thischar = fgetc($this->getid3->fp);
[2340] Fix | Delete
if (($prevchar == "\r") && ($thischar != "\n")) {
[2341] Fix | Delete
// read one byte too many, back up
[2342] Fix | Delete
fseek($this->getid3->fp, -1, SEEK_CUR);
[2343] Fix | Delete
break;
[2344] Fix | Delete
}
[2345] Fix | Delete
$buffer .= $thischar;
[2346] Fix | Delete
if ($thischar == "\n") {
[2347] Fix | Delete
break;
[2348] Fix | Delete
}
[2349] Fix | Delete
if (feof($this->getid3->fp)) {
[2350] Fix | Delete
break;
[2351] Fix | Delete
}
[2352] Fix | Delete
$prevchar = $thischar;
[2353] Fix | Delete
}
[2354] Fix | Delete
[2355] Fix | Delete
}
[2356] Fix | Delete
return $buffer;
[2357] Fix | Delete
}
[2358] Fix | Delete
[2359] Fix | Delete
/**
[2360] Fix | Delete
* @phpstan-impure
[2361] Fix | Delete
*
[2362] Fix | Delete
* @return bool
[2363] Fix | Delete
*/
[2364] Fix | Delete
protected function feof() {
[2365] Fix | Delete
if ($this->data_string_flag) {
[2366] Fix | Delete
return $this->data_string_position >= $this->data_string_length;
[2367] Fix | Delete
}
[2368] Fix | Delete
return feof($this->getid3->fp);
[2369] Fix | Delete
}
[2370] Fix | Delete
[2371] Fix | Delete
/**
[2372] Fix | Delete
* @param string $module
[2373] Fix | Delete
*
[2374] Fix | Delete
* @return bool
[2375] Fix | Delete
*/
[2376] Fix | Delete
final protected function isDependencyFor($module) {
[2377] Fix | Delete
return $this->dependency_to == $module;
[2378] Fix | Delete
}
[2379] Fix | Delete
[2380] Fix | Delete
/**
[2381] Fix | Delete
* @param string $text
[2382] Fix | Delete
*
[2383] Fix | Delete
* @return bool
[2384] Fix | Delete
*/
[2385] Fix | Delete
protected function error($text) {
[2386] Fix | Delete
$this->getid3->info['error'][] = $text;
[2387] Fix | Delete
[2388] Fix | Delete
return false;
[2389] Fix | Delete
}
[2390] Fix | Delete
[2391] Fix | Delete
/**
[2392] Fix | Delete
* @param string $text
[2393] Fix | Delete
*
[2394] Fix | Delete
* @return bool
[2395] Fix | Delete
*/
[2396] Fix | Delete
protected function warning($text) {
[2397] Fix | Delete
return $this->getid3->warning($text);
[2398] Fix | Delete
}
[2399] Fix | Delete
[2400] Fix | Delete
/**
[2401] Fix | Delete
* @param string $text
[2402] Fix | Delete
*/
[2403] Fix | Delete
protected function notice($text) {
[2404] Fix | Delete
// does nothing for now
[2405] Fix | Delete
}
[2406] Fix | Delete
[2407] Fix | Delete
/**
[2408] Fix | Delete
* @param string $name
[2409] Fix | Delete
* @param int $offset
[2410] Fix | Delete
* @param int $length
[2411] Fix | Delete
* @param string $image_mime
[2412] Fix | Delete
*
[2413] Fix | Delete
* @return string|null
[2414] Fix | Delete
*
[2415] Fix | Delete
* @throws Exception
[2416] Fix | Delete
* @throws getid3_exception
[2417] Fix | Delete
*/
[2418] Fix | Delete
public function saveAttachment($name, $offset, $length, $image_mime=null) {
[2419] Fix | Delete
$fp_dest = null;
[2420] Fix | Delete
$dest = null;
[2421] Fix | Delete
try {
[2422] Fix | Delete
[2423] Fix | Delete
// do not extract at all
[2424] Fix | Delete
if ($this->getid3->option_save_attachments === getID3::ATTACHMENTS_NONE) {
[2425] Fix | Delete
[2426] Fix | Delete
$attachment = null; // do not set any
[2427] Fix | Delete
[2428] Fix | Delete
// extract to return array
[2429] Fix | Delete
} elseif ($this->getid3->option_save_attachments === getID3::ATTACHMENTS_INLINE) {
[2430] Fix | Delete
[2431] Fix | Delete
$this->fseek($offset);
[2432] Fix | Delete
$attachment = $this->fread($length); // get whole data in one pass, till it is anyway stored in memory
[2433] Fix | Delete
if ($attachment === false || strlen($attachment) != $length) {
[2434] Fix | Delete
throw new Exception('failed to read attachment data');
[2435] Fix | Delete
}
[2436] Fix | Delete
[2437] Fix | Delete
// assume directory path is given
[2438] Fix | Delete
} else {
[2439] Fix | Delete
[2440] Fix | Delete
// set up destination path
[2441] Fix | Delete
$dir = rtrim(str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $this->getid3->option_save_attachments), DIRECTORY_SEPARATOR);
[2442] Fix | Delete
if (!is_dir($dir) || !getID3::is_writable($dir)) { // check supplied directory
[2443] Fix | Delete
throw new Exception('supplied path ('.$dir.') does not exist, or is not writable');
[2444] Fix | Delete
}
[2445] Fix | Delete
$dest = $dir.DIRECTORY_SEPARATOR.$name.($image_mime ? '.'.getid3_lib::ImageExtFromMime($image_mime) : '');
[2446] Fix | Delete
[2447] Fix | Delete
// create dest file
[2448] Fix | Delete
if (($fp_dest = fopen($dest, 'wb')) == false) {
[2449] Fix | Delete
throw new Exception('failed to create file '.$dest);
[2450] Fix | Delete
}
[2451] Fix | Delete
[2452] Fix | Delete
// copy data
[2453] Fix | Delete
$this->fseek($offset);
[2454] Fix | Delete
$buffersize = ($this->data_string_flag ? $length : $this->getid3->fread_buffer_size());
[2455] Fix | Delete
$bytesleft = $length;
[2456] Fix | Delete
while ($bytesleft > 0) {
[2457] Fix | Delete
if (($buffer = $this->fread(min($buffersize, $bytesleft))) === false || ($byteswritten = fwrite($fp_dest, $buffer)) === false || ($byteswritten === 0)) {
[2458] Fix | Delete
throw new Exception($buffer === false ? 'not enough data to read' : 'failed to write to destination file, may be not enough disk space');
[2459] Fix | Delete
}
[2460] Fix | Delete
$bytesleft -= $byteswritten;
[2461] Fix | Delete
}
[2462] Fix | Delete
[2463] Fix | Delete
fclose($fp_dest);
[2464] Fix | Delete
$attachment = $dest;
[2465] Fix | Delete
[2466] Fix | Delete
}
[2467] Fix | Delete
[2468] Fix | Delete
} catch (Exception $e) {
[2469] Fix | Delete
[2470] Fix | Delete
// close and remove dest file if created
[2471] Fix | Delete
if (isset($fp_dest) && is_resource($fp_dest)) {
[2472] Fix | Delete
fclose($fp_dest);
[2473] Fix | Delete
}
[2474] Fix | Delete
[2475] Fix | Delete
if (isset($dest) && file_exists($dest)) {
[2476] Fix | Delete
unlink($dest);
[2477] Fix | Delete
}
[2478] Fix | Delete
[2479] Fix | Delete
// do not set any is case of error
[2480] Fix | Delete
$attachment = null;
[2481] Fix | Delete
$this->warning('Failed to extract attachment '.$name.': '.$e->getMessage());
[2482] Fix | Delete
[2483] Fix | Delete
}
[2484] Fix | Delete
[2485] Fix | Delete
// seek to the end of attachment
[2486] Fix | Delete
$this->fseek($offset + $length);
[2487] Fix | Delete
[2488] Fix | Delete
return $attachment;
[2489] Fix | Delete
}
[2490] Fix | Delete
[2491] Fix | Delete
}
[2492] Fix | Delete
[2493] Fix | Delete
[2494] Fix | Delete
class getid3_exception extends Exception
[2495] Fix | Delete
{
[2496] Fix | Delete
public $message;
[2497] Fix | Delete
}
[2498] Fix | Delete
[2499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function