Created
June 27, 2012 14:05
-
-
Save soundws/3004257 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Get basedir | |
*/ | |
function basedir( $docroot = '/' ) | |
{ | |
$docroot = rtrim($docroot, '/\\').DIRECTORY_SEPARATOR; | |
$basedir = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); | |
if (isset($_SERVER['PATH_INFO'])) { | |
$basedir = substr($basedir, 0, -strlen($_SERVER['PATH_INFO'])); | |
} | |
$basename = substr($_SERVER['SCRIPT_FILENAME'], strlen($docroot)); | |
$len = strlen($basename); | |
if(substr($basedir, -$len) === $basename) { | |
$basedir = substr($basedir, 0, -$len); | |
} | |
return $basedir; | |
} | |
?> | |
<?php | |
define('BASEDIR', basedir(__DIR__)); | |
?> | |
<!DOCTYPE html> | |
<html lang="ja"> | |
<head> | |
<meta charse="UTF-8"> | |
<link rel="stylesheet" type="text/css" href="<?php echo BASEDIR; ?>css/default.css" /> | |
<script type="text/javascript" src="<?php echo BASEDIR; ?>js/default.js"></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment