* Removed redudant global decleration
[lhc/web/wiklou.git] / includes / StreamFile.php
1 <?php
2 /** */
3
4 /** */
5 function wfStreamFile( $fname ) {
6 global $wgSquidMaxage;
7 $stat = @stat( $fname );
8 if ( !$stat ) {
9 header( 'HTTP/1.0 404 Not Found' );
10 echo "<html><body>
11 <h1>File not found</h1>
12 <p>Although this PHP script ({$_SERVER['SCRIPT_NAME']}) exists, the file requested for output
13 does not.</p>
14 </body></html>";
15 return;
16 }
17
18 header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s', $stat['mtime'] ) . ' GMT' );
19
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" );
25 return;
26 }
27 }
28
29 header( 'Content-Length: ' . $stat['size'] );
30
31 $type = wfGetType( $fname );
32 if ( $type and $type!="unknown/unknown") {
33 header("Content-type: $type");
34 } else {
35 header('Content-type: application/x-wiki');
36 }
37
38 readfile( $fname );
39 }
40
41 /** */
42 function wfGetType( $filename ) {
43 global $wgTrivialMimeDetection;
44
45 # trivial detection by file extension,
46 # used for thumbnails (thumb.php)
47 if ($wgTrivialMimeDetection) {
48 $ext= strtolower(strrchr($filename, '.'));
49
50 switch ($ext) {
51 case '.gif': return 'image/gif';
52 case '.png': return 'image/png';
53 case '.jpg': return 'image/jpeg';
54 case '.jpeg': return 'image/jpeg';
55 }
56
57 return 'unknown/unknown';
58 }
59 else {
60 $magic=& wfGetMimeMagic();
61 return $magic->guessMimeType($filename); //full fancy mime detection
62 }
63 }
64
65 ?>