Beispiel #1
0
 static function makeRex()
 {
     return str::bc36(strval(time()) . str_replace('.', '', $_SERVER['REMOTE_ADDR']));
 }
Beispiel #2
0
 static function drawFile($fname)
 {
     // settings
     ini_set('zlib.output_compression', 'Off');
     ini_set('output_buffering', 'Off');
     // clean output buffers
     for ($i = 0; $i < ob_get_level(); $i++) {
         ob_end_clean();
         if ($i > 10) {
             break;
         }
     }
     // content-type based on extension
     $types = array('default' => array('type' => 'application/octet-stream', 'attach' => true), 'mp3' => 'audio/mpeg', 'mov' => 'video/quicktime', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'gif' => 'image/gif', 'pdf' => 'application/pdf', 'zip' => array('type' => 'application/zip', 'attach' => true), 'doc' => array('type' => 'application/msword', 'attach' => true));
     // get type
     $ext = file::ext($fname);
     $t = isset($types[$ext]) ? $types[$ext] : current($types);
     if (!is_array($t)) {
         $t = array('type' => $t);
     }
     // headers
     $id = str::bc36(time());
     $chunk = 1024 * 1024;
     $time_limit = (int) ($chunk / 100);
     $filesize = filesize($fname);
     header("Cache-Control:");
     header("Cache-Control: public");
     header("Pragma: ");
     header('Content-Type: ' . $t['type']);
     header('Content-Disposition: ' . ($t['attach'] ? 'attachment' : 'inline') . ';' . ' filename="' . basename($fname) . '"');
     //' filename="'.file::name($fname).'-'.$id.'.'.file::ext($fname).'"');
     header("Content-Transfer-Encoding: binary\n");
     // check if http_range is sent by browser (or download manager)
     header("Accept-Ranges: bytes");
     if (isset($_SERVER['HTTP_RANGE'])) {
         list($a, $range) = explode("=", $_SERVER['HTTP_RANGE']);
         str_replace($range, "-", $range);
         $filesize2 = $filesize - 1;
         $new_length = $filesize2 - $range;
         header("HTTP/1.1 206 Partial Content");
         header("Content-Length: {$new_length}");
         header("Content-Range: bytes {$range}{$filesize2}/{$filesize}");
         $filesize = $new_length;
     } else {
         $filesize2 = $filesize - 1;
         header("Content-Range: bytes 0-{$filesize2}/{$filesize}");
     }
     header("Content-Length: " . $filesize);
     // draw
     $fp = fopen($fname, 'rb');
     if ($fp) {
         // resume
         if ($range > 0) {
             fseek($fp, $range);
         }
         // send
         while (!feof($fp) and connection_status() == 0) {
             set_time_limit($time_limit);
             $content = fread($fp, $chunk);
             echo $content;
             ob_flush();
             flush();
             $sent += strlen($content);
             unset($content);
             //funx::debug("$id sent ".(int)($sent/1024)."k".
             //	", memory used ".(int)(memory_get_usage(true)/1024)."k".
             //	", time limit ".(int)($time_limit/60)."m");
         }
         fclose($fp);
     }
     funx::debug("{$id} done ({$sent} of {$filesize}) (connection_status==" . (int) connection_status() . ")");
     return !connection_aborted() and connection_status() == 0 and $sent >= $filesize;
 }