5 function wfStreamFile( $fname ) {
6 $stat = @stat
( $fname );
8 header( 'HTTP/1.0 404 Not Found' );
9 header( 'Cache-Control: no-cache' );
10 header( 'Content-Type: text/html' );
11 $encFile = htmlspecialchars( $fname );
12 $encScript = htmlspecialchars( $_SERVER['SCRIPT_NAME'] );
14 <h1>File not found</h1>
15 <p>Although this PHP script ($encScript) exists, the file requested for output
16 ($encFile) does not.</p>
22 header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s', $stat['mtime'] ) . ' GMT' );
24 // Cancel output buffering and gzipping if set
25 while( $status = ob_get_status() ) {
27 if( $status['name'] == 'ob_gzhandler' ) {
28 header( 'Content-Encoding:' );
32 $type = wfGetType( $fname );
33 if ( $type and $type!="unknown/unknown") {
34 header("Content-type: $type");
36 header('Content-type: application/x-wiki');
39 if ( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
40 $modsince = preg_replace( '/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE'] );
41 $sinceTime = strtotime( $modsince );
42 if ( $stat['mtime'] <= $sinceTime ) {
43 header( "HTTP/1.0 304 Not Modified" );
48 header( 'Content-Length: ' . $stat['size'] );
54 function wfGetType( $filename ) {
55 global $wgTrivialMimeDetection;
57 # trivial detection by file extension,
58 # used for thumbnails (thumb.php)
59 if ($wgTrivialMimeDetection) {
60 $ext= strtolower(strrchr($filename, '.'));
63 case '.gif': return 'image/gif';
64 case '.png': return 'image/png';
65 case '.jpg': return 'image/jpeg';
66 case '.jpeg': return 'image/jpeg';
69 return 'unknown/unknown';
72 $magic=& MimeMagic
::singleton();
73 return $magic->guessMimeType($filename); //full fancy mime detection