Esempio n. 1
0
File: fetch.php Progetto: rair/yacs
 // record surfer activity
 Activities::post('file:' . $item['id'], 'fetch');
 $anchor->touch('file:fetch', 'file:' . $item['id'], true);
 // if we have an external reference, use it
 if (isset($item['file_href']) && $item['file_href']) {
     $target_href = $item['file_href'];
     // we have direct access to the file
 } else {
     // ensure a valid file name
     $file_name = utf8::to_ascii($item['file_name']);
     // where the file is located
     $path = Files::get_path($item['anchor']) . '/' . $item['file_name'];
     // file attributes
     $attributes = array();
     // transmit file content
     if (!headers_sent() && ($handle = Safe::fopen($context['path_to_root'] . $path, "rb")) && ($stat = Safe::fstat($handle))) {
         // stream FLV files if required to do so
         if (substr($item['file_name'], -4) == '.flv' && isset($_REQUEST['position']) && $_REQUEST['position'] > 0 && $_REQUEST['position'] < $stat['size']) {
             Safe::header('Content-Length: ' . ($stat['size'] - $_REQUEST['position'] + 13));
             echo 'FLV' . pack('C', 1) . pack('C', 1) . pack('N', 9) . pack('N', 9);
             fseek($handle, $_REQUEST['position']);
             echo fread($handle, $stat['size'] - $_REQUEST['position']);
             fclose($handle);
             return;
         }
         // load some file parser if one is available
         $analyzer = NULL;
         if (is_readable($context['path_to_root'] . 'included/getid3/getid3.php')) {
             include_once $context['path_to_root'] . 'included/getid3/getid3.php';
             $analyzer = new getid3();
         }