5 function wfStreamFile( $fname ) {
7 $stat = @stat
( $fname );
9 header( 'HTTP/1.0 404 Not Found' );
11 <h1>File not found</h1>
12 <p>Although this PHP script ({$_SERVER['SCRIPT_NAME']}) exists, the file requested for output
18 header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s', $stat['mtime'] ) . ' GMT' );
20 if ( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
21 $modsince = preg_replace( '/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE'] );
22 $sinceTime = strtotime( $modsince );
23 if ( $stat['mtime'] <= $sinceTime ) {
24 header( "HTTP/1.0 304 Not Modified" );
29 header( 'Content-Length: ' . $stat['size'] );
31 $type = wfGetType( $fname );
32 if ( $type and $type!="unknown/unknown") {
33 header("Content-type: $type");
35 header('Content-type: application/x-wiki');
42 function wfGetType( $filename ) {
43 global $wgTrivialMimeDetection;
45 # trivial detection by file extension,
46 # used for thumbnails (thumb.php)
47 if ($wgTrivialMimeDetection) {
48 $ext= strtolower(strrchr($filename, '.'));
51 case '.gif': return 'image/gif';
52 case '.png': return 'image/png';
53 case '.jpg': return 'image/jpeg';
54 case '.jpeg': return 'image/jpeg';
57 return 'unknown/unknown';
60 $magic=& wfGetMimeMagic();
61 return $magic->guessMimeType($filename); //full fancy mime detection