diff --git a/src/index.php b/src/index.php index 3705083..1198bd8 100644 --- a/src/index.php +++ b/src/index.php @@ -1,215 +1,252 @@ + +

wrong parameter : + "" +

+ + + +

File not found: + "" +

+ + '; + return ''.htmlentities($alt).''; + return ''; } - if (isset($_GET["img"])) { - if (ereg('[^-_.A-Za-z0-9]', $_GET["img"])) { -?> - -

Illegal Image name: ""

- - - - -

Image not found: ""

- - - - -

Illegal Video name: ""

- - -/dev/null'); - break; - case "mp4": - header('Content-type: video/mp4'); - exec('ffmpeg -i "'.$DIR.'/'.$_GET["video"].'" -qscale 4 -vcodec libx264 -f mp4 - 2>/dev/null'); - break; - } - } else { */ -// Clears the cache and prevent unwanted output -ob_clean(); -@ini_set('error_reporting', E_ALL & ~ E_NOTICE); -@apache_setenv('no-gzip', 1); -@ini_set('zlib.output_compression', 'Off'); - -if (isset($_GET["mime"])) - $file = $CONVERT.'/'.$_GET["mime"].'/'.preg_replace('/\.[^.]*$/', '.'.$_GET["mime"], $_GET["video"]); -else - $file = $DIR.'/'.$_GET["video"]; // The media file's location -$size = filesize($file); // The size of the file -$mime = mime_content_type($file); +/** Generate a source entry for a given file. + Returns source tag, if the image file exists, empty otherwise. */ +function source($dir, $file, $mime=NULL) { + $URL=pageUrl(); + $path=$dir.'/'.$file; + if (is_file($path)) { + if (!$mime) $type=mime_content_type($path); + else $type='video/'.$mime; + echo ''; + } else { + return ''; + } +} -// Send the content type header -header('Content-type: ' . $mime); - -// Check if it's a HTTP range request -if(isset($_SERVER['HTTP_RANGE'])){ - // Parse the range header to get the byte offset - $ranges = array_map( - 'intval', // Parse the parts into integer - explode( - '-', // The range separator - substr($_SERVER['HTTP_RANGE'], 6) // Skip the `bytes=` part of the header - ) - ); - - // If the last range param is empty, it means the EOF (End of File) - if(!$ranges[1]){ - $ranges[1] = $size - 1; - } - - // Send the appropriate headers - header('HTTP/1.1 206 Partial Content'); - header('Accept-Ranges: bytes'); - header('Content-Length: ' . ($ranges[1] - $ranges[0])); // The size of the range - - // Send the ranges we offered - header( - sprintf( - 'Content-Range: bytes %d-%d/%d', // The header format - $ranges[0], // The start range - $ranges[1], // The end range - $size // Total size of the file - ) - ); +/** Output only a part of a file */ +function range($path, $size, $mime) { + $ranges = array_map('intval', // Parse the parts into integer + explode('-', // The range separator + // Skip the `bytes=` part of the header + substr($_SERVER['HTTP_RANGE'], 6))); + // If the last range param is empty, it means the EOF (End of File) + if (!$ranges[1]) $ranges[1] = $size-1; + + // Send the appropriate headers + header('HTTP/1.1 206 Partial Content'); + header('Accept-Ranges: bytes'); + header('Content-Length: '.($ranges[1]-$ranges[0])); // The size of the range - // It's time to output the file - $f = fopen($file, 'rb'); // Open the file in binary mode - $chunkSize = 8192; // The size of each chunk to output - - // Seek to the requested start range - fseek($f, $ranges[0]); - - // Start outputting the data - while(true){ - // Check if we have outputted all the data requested - if(ftell($f) >= $ranges[1]){ - break; - } + // Send the ranges we offered + header(sprintf('Content-Range: bytes %d-%d/%d', // The header format + $ranges[0], // The start range + $ranges[1], // The end range + $size)); // Total size of the file + + // It's time to output the file + $f = fopen($file, 'rb'); // Open the file in binary mode + $chunkSize = 8192; // The size of each chunk to output - // Output the data - echo fread($f, $chunkSize); + // Seek to the requested start range + fseek($f, $ranges[0]); - // Flush the buffer immediately - @ob_flush(); - flush(); - } + // output the data + while (ftell($f) < $ranges[1]) { + echo fread($f, $chunkSize); + @ob_flush(); + flush(); + } } -else { - // It's not a range request, output the file anyway + +/** Output a file */ +function output($path) { + $size = filesize($path); // The size of the file + $mime = mime_content_type($path); + ob_clean(); + @ini_set('error_reporting', E_ALL & ~ E_NOTICE); + @apache_setenv('no-gzip', 1); + @ini_set('zlib.output_compression', 'Off'); + header('Content-type: ' . $mime); + if (isset($_SERVER['HTTP_RANGE'])) { + range($path, $size, $mime); + } else { header('Content-Length: ' . $size); - - // Read the file @readfile($file); - - // and flush the buffer @ob_flush(); flush(); + } + exit; } -// } - } else { -?> - - -

-
-[Click to Download or copy link to VLC player] -

+/** Replace file extension */ +function ext($file, $newext) { + return preg_replace('/\.[^.]*$/', '.'.$newext, $file); +} - - - + + +

+ +
+ [Click to Download or + copy link to VLC player] +

+ + + + Videofilme + + + +

Videofilme

+ + + - -

Video not found: ""

- - - - - - - -

Videofilme

- - - -