5 function wfStreamFile( $fname, $headers = array() ) {
6 $stat = @stat
( $fname );
8 header( 'HTTP/1.0 404 Not Found' );
9 header( 'Cache-Control: no-cache' );
10 header( 'Content-Type: text/html; charset=utf-8' );
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 wfResetOutputBuffers();
27 $type = wfGetType( $fname );
28 if ( $type and $type!="unknown/unknown") {
29 header("Content-type: $type");
31 header('Content-type: application/x-wiki');
34 global $wgContLanguageCode;
35 header( "Content-Disposition: inline;filename*=utf-8'$wgContLanguageCode'" . urlencode( basename( $fname ) ) );
37 foreach ( $headers as $header ) {
41 if ( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
42 $modsince = preg_replace( '/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE'] );
43 $sinceTime = strtotime( $modsince );
44 if ( $stat['mtime'] <= $sinceTime ) {
45 header( "HTTP/1.0 304 Not Modified" );
50 header( 'Content-Length: ' . $stat['size'] );
56 function wfGetType( $filename ) {
57 global $wgTrivialMimeDetection;
59 # trivial detection by file extension,
60 # used for thumbnails (thumb.php)
61 if ($wgTrivialMimeDetection) {
62 $ext= strtolower(strrchr($filename, '.'));
65 case '.gif': return 'image/gif';
66 case '.png': return 'image/png';
67 case '.jpg': return 'image/jpeg';
68 case '.jpeg': return 'image/jpeg';
71 return 'unknown/unknown';
74 $magic = MimeMagic
::singleton();
75 return $magic->guessMimeType($filename); //full fancy mime detection