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