5 function wfStreamFile( $fname ) {
6 $stat = @stat
( $fname );
8 header( 'HTTP/1.0 404 Not Found' );
10 <h1>File not found</h1>
11 <p>Although this PHP script ({$_SERVER['SCRIPT_NAME']}) exists, the file requested for output
17 header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s', $stat['mtime'] ) . ' GMT' );
19 // Cancel output buffering and gzipping if set
20 while( $status = ob_get_status() ) {
22 if( $status['name'] == 'ob_gzhandler' ) {
23 header( 'Content-Encoding:' );
27 $type = wfGetType( $fname );
28 if ( $type and $type!="unknown/unknown") {
29 header("Content-type: $type");
31 header('Content-type: application/x-wiki');
34 if ( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
35 $modsince = preg_replace( '/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE'] );
36 $sinceTime = strtotime( $modsince );
37 if ( $stat['mtime'] <= $sinceTime ) {
38 header( "HTTP/1.0 304 Not Modified" );
43 header( 'Content-Length: ' . $stat['size'] );
49 function wfGetType( $filename ) {
50 global $wgTrivialMimeDetection;
52 # trivial detection by file extension,
53 # used for thumbnails (thumb.php)
54 if ($wgTrivialMimeDetection) {
55 $ext= strtolower(strrchr($filename, '.'));
58 case '.gif': return 'image/gif';
59 case '.png': return 'image/png';
60 case '.jpg': return 'image/jpeg';
61 case '.jpeg': return 'image/jpeg';
64 return 'unknown/unknown';
67 $magic=& wfGetMimeMagic();
68 return $magic->guessMimeType($filename); //full fancy mime detection