3 ini_set('display_errors', 1);
4 error_reporting(E_ALL
);
6 if ( isset( $_SERVER["SCRIPT_FILENAME"] ) ) {
7 $file = $_SERVER["SCRIPT_FILENAME"];
8 if ( !is_readable( $file ) ) {
9 // Let the server throw the error
12 $ext = pathinfo( $file, PATHINFO_EXTENSION
);
13 if ( $ext == 'php' ||
$ext == 'php5' ) {
15 # We use require and return true here because when you return false
16 # the php webserver will discard post data and things like login
17 # will not function in the dev environment.
22 $lines = explode( "\n", file_get_contents( "includes/mime.types" ) );
23 foreach ( $lines as $line ) {
24 $exts = explode( " ", $line );
25 $mime = array_shift( $exts );
26 if ( in_array( $ext, $exts ) ) {
27 break; # this is the right value for $mime
32 $basename = basename( $file );
33 if ( $basename == strtoupper( $basename ) ) {
34 # IF it's something like README serve it as text
39 # Use custom handling to serve files with a known mime type
40 # This way we can serve things like .svg files that the built-in
41 # PHP webserver doesn't understand.
42 # ;) Nicely enough we just happen to bundle a mime.types file
43 $f = fopen($file, 'rb');
44 if ( preg_match( '^text/', $mime ) ) {
45 # Text should have a charset=UTF-8 (php's webserver does this too)
46 header("Content-Type: $mime; charset=UTF-8");
48 header("Content-Type: $mime");
50 header("Content-Length: " . filesize($file));
51 // Stream that out to the browser
57 # Let the php server handle things on it's own otherwise