| Index: trunk/phase3/maintenance/dev/router.php |
| — | — | @@ -0,0 +1,52 @@ |
| | 2 | +<?php |
| | 3 | + |
| | 4 | +if ( isset( $_SERVER["SCRIPT_FILENAME"] ) ) { |
| | 5 | + $file = $_SERVER["SCRIPT_FILENAME"]; |
| | 6 | + if ( !is_readable( $file ) ) { |
| | 7 | + // Let the server throw the error |
| | 8 | + return false; |
| | 9 | + } |
| | 10 | + $ext = pathinfo( $file, PATHINFO_EXTENSION ); |
| | 11 | + if ( $ext == 'php' ) { |
| | 12 | + # Let it execute php files |
| | 13 | + return false; |
| | 14 | + } |
| | 15 | + $mime = false; |
| | 16 | + $lines = explode( "\n", file_get_contents( "includes/mime.types" ) ); |
| | 17 | + foreach ( $lines as $line ) { |
| | 18 | + $exts = explode( " ", $line ); |
| | 19 | + $mime = array_shift( $exts ); |
| | 20 | + if ( in_array( $ext, $exts ) ) { |
| | 21 | + break; # this is the right value for $mime |
| | 22 | + } |
| | 23 | + $mime = false; |
| | 24 | + } |
| | 25 | + if ( !$mime ) { |
| | 26 | + $basename = basename( $file ); |
| | 27 | + if ( $basename == strtoupper( $basename ) ) { |
| | 28 | + # IF it's something like README serve it as text |
| | 29 | + $mime = "text/plain"; |
| | 30 | + } |
| | 31 | + } |
| | 32 | + if ( $mime ) { |
| | 33 | + # Use custom handling to serve files with a known mime type |
| | 34 | + # This way we can serve things like .svg files that the built-in |
| | 35 | + # PHP webserver doesn't understand. |
| | 36 | + # ;) Nicely enough we just happen to bundle a mime.types file |
| | 37 | + $f = fopen($file, 'rb'); |
| | 38 | + if ( preg_match( '^text/', $mime ) ) { |
| | 39 | + # Text should have a charset=UTF-8 (php's webserver does this too) |
| | 40 | + header("Content-Type: $mime; charset=UTF-8"); |
| | 41 | + } else { |
| | 42 | + header("Content-Type: $mime"); |
| | 43 | + } |
| | 44 | + header("Content-Length: " . filesize($file)); |
| | 45 | + // Stream that out to the browser |
| | 46 | + fpassthru($f); |
| | 47 | + return true; |
| | 48 | + } |
| | 49 | +} |
| | 50 | + |
| | 51 | +# Let the php server handle things on it's own otherwise |
| | 52 | +return false; |
| | 53 | + |
| Index: trunk/phase3/maintenance/dev/start.sh |
| — | — | @@ -18,4 +18,4 @@ |
| 19 | 19 | echo "" |
| 20 | 20 | |
| 21 | 21 | cd "$DEV/../../"; # $IP |
| 22 | | -"$PHP" -S "localhost:$PORT" |
| | 22 | +"$PHP" -S "localhost:$PORT" "$DEV/router.php" |