// create name and path for temp image if ($fp_local = fopen($localtempfile, 'wb')) { while ($buffer = @fread($fp_remote, 8192)) { // read remote image //mysqltest(); fwrite($fp_local, $buffer); // write to local temp image } } @fclose($fp_local); @fclose($fp_remote); } else { // if not impossible to open by PHP function 'fopen()', try to open this image by means of cURL library if ($curl == '1') { // if cURL library if ($buffer = curl_open($link)) { $localtempfile = tempnam('./tmp', 'img'); if ($fp_local = fopen($localtempfile, 'wb')) { fwrite($fp_local, $buffer); } else { $unreachable = '1'; // unable to write to temp-file } fclose($fp_local); } else { $unreachable = '2'; // unable to open the remote file by cURL } } else { $unreachable = '3'; // no cURL library available
function get_id3string($link, $build_tmp, $cl) { global $clear, $case_sensitive, $curl, $debug; $error = ''; $id3_string = ''; $localtempfile = $link; $unreachable = ''; if ($build_tmp == '1') { // we need to build a temporary file mysqltest(); if ($fp_remote = @fopen($link, 'rb')) { $localtempfile = tempnam('./tmp', 'getID3'); if ($fp_local = fopen($localtempfile, 'wb')) { // this will read the first 64 kByte of the media file for ($i = 1; $i <= 4; $i++) { $buffer = @fread($fp_remote, 8192); fwrite($fp_local, $buffer); } fclose($fp_local); } } else { // if impossible to open by PHP function 'fopen()', try to open this image by means of cURL library if ($curl == '1') { // if cURL library is available if ($buffer = curl_open($link)) { $localtempfile = tempnam('./tmp', 'getID3'); if ($fp_local = fopen($localtempfile, 'wb')) { fwrite($fp_local, $buffer); } else { $unreachable = '1'; // unable to write to temp-file } fclose($fp_local); } else { $unreachable = '2'; // unable to open the remote file by cURL } } else { $unreachable = '3'; // no cURL library available } } if ($debug == '2') { if ($unreachable) { if ($unreachable == '1') { $report = "Unable to write to temp-file."; } if ($unreachable == '2') { $report = "Unable to open the remote media file {$link} by cURL function."; } if ($unreachable == '3') { $report = "Unable to open media file {$link} by means of PHP function fopen(), nor cURL library available."; } printWarning($report, $cl); } } } // Remote files are not supported if (!preg_match('/^(ht|f)tp:\\/\\//', $localtempfile) && !$unreachable) { $getID3 = new getID3(); // Initialize getID3 engine $getid3->encoding = 'UTF-8'; try { $This_ID3 = $getID3->analyze($localtempfile); } catch (Exception $e) { $rep = $e->message; $report = "Problem when analysing media file. " . $rep . "."; printWarning($report, $cl); } if ($build_tmp == '1') { unlink($localtempfile); // Delete temporary file fclose($fp_remote); } $id3_array = array(); foreach ($This_ID3 as $key0 => $val0) { // prepare all relevant ID3 and EXIF information into array if (is_array($val0)) { foreach ($This_ID3 as $key1 => $section1) { foreach ($section1 as $name1 => $val1) { if (is_array($val1)) { foreach ($val1 as $key2 => $section2) { foreach ($section2 as $name2 => $val2) { if (is_array($val2)) { // for future releases } else { if (strlen($val2) < 100 && $key2 != "THUMBNAIL" && $key2 != "keyframes" && $val2 != "") { //echo "2 $key2.$name2: $val2<br />\n"; $id3_array[] = " " . $key2 . " >> " . $name2 . " ;; " . $val2 . " "; } } } } } else { if (strlen($val1) < 100 && $val1 != "") { //echo "1 $key1.$name1: $val1<br />\n"; $id3_array[] = " " . $key1 . " >> " . $name1 . " ;; " . $val1 . " "; } } } } } else { if ($key0 != "GETID3_VERSION") { //echo "0 $key0: $val0<br />\n"; $id3_array[] = " >> " . $key0 . " ;; " . $val0 . " "; } } } sort($id3_array); $id3_string = implode("<br />", array_unique($id3_array)); // convert array into string with <br /> as delimiter if ($case_sensitive == '0') { $id3_string = lower_ent($id3_string); $id3_string = lower_case($id3_string); } if ($clear == '1') { unset($key0, $key1, $key2, $name1, $name2, $val0, $val1, $val2); unset($section1, $section2, $This_ID3, $getID3); $id3_array = array(); } } return $id3_string; }