5 function wfStreamFile( $fname ) {
6 $stat = @stat
( $fname );
8 header( 'HTTP/1.0 404 Not Found' );
9 $encFile = htmlspecialchars( $fname );
10 $encScript = htmlspecialchars( $_SERVER['SCRIPT_NAME'] );
12 <h1>File not found</h1>
13 <p>Although this PHP script ($encScript) exists, the file requested for output
14 ($encFile) does not.</p>
19 header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s', $stat['mtime'] ) . ' GMT' );
21 // Cancel output buffering and gzipping if set
22 while( $status = ob_get_status() ) {
24 if( $status['name'] == 'ob_gzhandler' ) {
25 header( 'Content-Encoding:' );
29 $type = wfGetType( $fname );
30 if ( $type and $type!="unknown/unknown") {
31 header("Content-type: $type");
33 header('Content-type: application/x-wiki');
36 if ( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
37 $modsince = preg_replace( '/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE'] );
38 $sinceTime = strtotime( $modsince );
39 if ( $stat['mtime'] <= $sinceTime ) {
40 header( "HTTP/1.0 304 Not Modified" );
45 header( 'Content-Length: ' . $stat['size'] );
51 function wfGetType( $filename ) {
52 global $wgTrivialMimeDetection;
54 # trivial detection by file extension,
55 # used for thumbnails (thumb.php)
56 if ($wgTrivialMimeDetection) {
57 $ext= strtolower(strrchr($filename, '.'));
60 case '.gif': return 'image/gif';
61 case '.png': return 'image/png';
62 case '.jpg': return 'image/jpeg';
63 case '.jpeg': return 'image/jpeg';
66 return 'unknown/unknown';
69 $magic=& MimeMagic
::singleton();
70 return $magic->guessMimeType($filename); //full fancy mime detection