나는 많은 정보를 검색할 수 있으며, 다양한 솔루션과 높고 낮은 com/go/4e6b330a_kr redboot*용 내려받습니다 절대 경로. 하지만 아닌 다른 특정 조건에서 일할 수 있는 것처럼 보인다. 그 안에는 1 개의 은메달 글머리표 방법은 PHP 스크립트에서 실행됨을 절대 경로? 하지만, 나를 위해 스크립트가 실행될 경우 명령줄에서 솔루션 기능을 할 뿐 아니라, 그냥 내 실행하십시오 Apache 상술합니다.
현재 파일 경로를 '' FILE 상수입니다 부여하느뇨 상대경로를 있습니다.
문제는 어떻게 하나님께용서를 변경된 읽어들이려면 대신 처음에 수행되 스크립트입니다 현재 실행 중인 스크립트입니다. 유일한 (?) 그렇게 할 수 있는 'debug_backtrace' 기능을 사용할 수 있다.
$stack = debug_backtrace();
$firstFrame = $stack[count($stack) - 1];
$initialFile = $firstFrame['file'];
예: # 'https://' var = 블레이블레 555 (korea. emc.) example.com/subFolder/myfile.php?
// ======= PATHINFO ====== //
$x = pathinfo($url);
$x['dirname'] 🡺 https://example.com/subFolder
$x['basename'] 🡺 myfile.php?
$x['extension'] 🡺 php?k=blaa#12345 // Unsecure! also, read my notice about hashtag parts
$x['filename'] 🡺 myfile
// ======= PARSE_URL ====== //
$x = parse_url($url);
$x['scheme'] 🡺 https
$x['host'] 🡺 example.com
$x['path'] 🡺 /subFolder/myfile.php
$x['query'] 🡺 k=blaa
$x['fragment'] 🡺 12345 // ! read my notice about hashtag parts
//=================================================== //
//========== self-defined SERVER variables ========== //
//=================================================== //
$_SERVER["DOCUMENT_ROOT"] 🡺 /home/user/public_html
$_SERVER["SERVER_ADDR"] 🡺 143.34.112.23
$_SERVER["SERVER_PORT"] 🡺 80(or 443 etc..)
$_SERVER["REQUEST_SCHEME"] 🡺 https //similar: $_SERVER["SERVER_PROTOCOL"]
$_SERVER['HTTP_HOST'] 🡺 example.com (or with WWW) //similar: $_SERVER["ERVER_NAME"]
$_SERVER["REQUEST_URI"] 🡺 /subFolder/myfile.php?k=blaa
$_SERVER["QUERY_STRING"] 🡺 k=blaa
__FILE__ 🡺 /home/user/public_html/subFolder/myfile.php
__DIR__ 🡺 /home/user/public_html/subFolder //same: dirname(__FILE__)
$_SERVER["REQUEST_URI"] 🡺 /subFolder/myfile.php?k=blaa
parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH)🡺 /subFolder/myfile.php
$_SERVER["PHP_SELF"] 🡺 /subFolder/myfile.php
// ==================================================================//
//if "myfile.php" is included in "PARENTFILE.php" , and you visit "PARENTFILE.PHP?abc":
$_SERVER["SCRIPT_FILENAME"]🡺 /home/user/public_html/parentfile.php
$_SERVER["PHP_SELF"] 🡺 /parentfile.php
$_SERVER["REQUEST_URI"] 🡺 /parentfile.php?abc
__FILE__ 🡺 /home/user/public_html/subFolder/myfile.php
// =================================================== //
// ================= handy variables ================= //
// =================================================== //
//If site uses HTTPS:
$HTTP_or_HTTPS = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS']!=='off') || $_SERVER['SERVER_PORT']==443) ? 'https://':'http://' ); //in some cases, you need to add this condition too: if ('https'==$_SERVER['HTTP_X_FORWARDED_PROTO']) ...
//To trim values to filename, i.e.
basename($url) 🡺 myfile.php
//excellent solution to find origin
$debug_files = debug_backtrace();
$caller_file = count($debug_files) ? $debug_files[count($debug_files) - 1]['file'] : __FILE__;
표시문!:
< br/>; _
//(let's say, if wordpress is installed in subdirectory: http://example.com/wpdir/)
home_url() 🡺 http://example.com/wpdir/ //if is_ssl() is true, then it will be "https"
get_stylesheet_directory_uri() 🡺 http://example.com/wpdir/wp-content/themes/THEME_NAME [same: get_bloginfo('template_url') ]
get_stylesheet_directory() 🡺 /home/user/public_html/wpdir/wp-content/themes/THEME_NAME
plugin_dir_url(__FILE__) 🡺 http://example.com/wpdir/wp-content/themes/PLUGIN_NAME
plugin_dir_path(__FILE__) 🡺 /home/user/public_html/wpdir/wp-content/plugins/PLUGIN_NAME/
__DIR__
[직접] 에서 (http://php.net/manual/en/language.constants.predefined.php):
< blockquote>; 이 디렉터리이고 절실해졌습니다. 사용되는 경우 등이 포함된 파일 내의 디렉토리에는 반환됨. Dirname 에 해당하는 것이다. (FILE) 이 < code> /code> <;;). 루트 디렉토리 이름 뒤에 슬래시 (slash) 이 없는 것이 아니라면, 디렉터리입니다. < /blockquote>;
< blockquote>; ,,,, /b> < /code> FILE< code> < b> < 항상 포함되어 있는 반면 절대 경로가 심볼릭 해결되었으므로 이전 버전에서 (액세스보다 4.0.2) 이 상대 경로를 v2.03-00 상황에 따라. < /blockquote>;
'Get_included_files' 기능을 사용할 수 있는 최적의 솔루션을 있다.
list($scriptPath) = get_included_files();
이 경우에도 초기 스크립트입니다 부여하느뇨 절대 경로 있습니다.
이 기능이 포함된 파일 내부에 배치된
현재 작업 디렉터리를 초기 script& # 39 의 디렉터리입니다 다르다.
는 CLI 와 함께 스크립트입니다 csetup 상대 경로로
여기에서는 두 테스트 스크립트. 기본 스크립트 및 포함된 파일:
# C:\Users\Redacted\Desktop\main.php
include __DIR__ . DIRECTORY_SEPARATOR . 'include.php';
echoScriptPath();
# C:\Users\Redacted\Desktop\include.php
function echoScriptPath() {
list($scriptPath) = get_included_files();
echo 'The script being executed is ' . $scriptPath;
}
그 결과. 현재 디이브이 디렉터리입니다.
C:\>php C:\Users\Redacted\Desktop\main.php
The script being executed is C:\Users\Redacted\Desktop\main.php
<, http://php.net/manual/en/function.getcwd.php>.
예를 들어 '에서' 와 'FILE 반환되므로 C:\xampp\htdocs\index.php' 대신 '' C:\xampp\htdocs\ 삼중평균 파일_이름 XAMPP
dirname(__FILE__)
예제 파일을:
www/http/html/index.php. 이 경우 이 코드 내에 배치하십시오 이네스.프프 반환되므로:
'< php,? dirname (FILE), 에코 // 이 반환되므로: www/http/html/ '
www/http/html/class/myclass.php. 이 경우 이 코드 내에 배치하십시오 니클라스 s.프프 반환되므로:
'< php,? dirname (FILE), 에코 // 이 반환되므로: www/http/html/class/ '
/**
* Get the file path/dir from which a script/function was initially executed
*
* @param bool $include_filename include/exclude filename in the return string
* @return string
*/
function get_function_origin_path($include_filename = true) {
$bt = debug_backtrace();
array_shift($bt);
if ( array_key_exists(0, $bt) && array_key_exists('file', $bt[0]) ) {
$file_path = $bt[0]['file'];
if ( $include_filename === false ) {
$file_path = str_replace(basename($file_path), '', $file_path);
}
} else {
$file_path = null;
}
return $file_path;
}
이것이 내가 사용 및 작동하잖아 Linux 환경에서. # 39, 이는 내가 don& Windows 시스템에서 사용할 수 없는 것 같습니다.
//define canonicalized absolute pathname for the script
if(substr($_SERVER['SCRIPT_NAME'],0,1) == DIRECTORY_SEPARATOR) {
//does the script name start with the directory separator?
//if so, the path is defined from root; may have symbolic references so still use realpath()
$script = realpath($_SERVER['SCRIPT_NAME']);
} else {
//otherwise prefix script name with the current working directory
//and use realpath() to resolve symbolic references
$script = realpath(getcwd() . DIRECTORY_SEPARATOR . $_SERVER['SCRIPT_NAME']);
}
가장 쉬운 방법은 절대 경로, 이를 통해 처음 수행되 스크립트입니다 읽어들입니다 " main". '등이 포함된', '필요한 모든 스크립트입니다 스크립트입니다 require_once' 는 ',' 한 주 시작 부분에 상수입니다 저장함으로써 스크립트입니다.
define( 'SCRIPT_ROOT', __FILE__ );
'길' FILE 되돌려줍니다 현재 스크립트입니다. , 포함된 파일이 포함된 스크립트입니다 안쪽에 사용되는 되돌려줍니다 길을 묻는 것은 처음에 스크립트입니다 실행하십시오 OP 있다.
>, 설명: 우리는 현재 초기 수행되 스크립트입니다 파일이 아닌,
'' 에 비해 더 빠르고 쉽게 저장할 수 있는 솔루션이 FILE 상수 () 는 경로 검색 debug_backtrace 사용하여 ' ()'
이 솔루션은 단일 " 위에 있을 때, main" 적합하다. 다른 모든 필요한 대부분의 웹 애플리케이션 '의 스크립트입니다 스크립트입니다 포함시키십시오 같이.
if( ! defined( 'SCRIPT_ROOT' ) ) {
define( 'SCRIPT_ROOT`, __FILE__ );
}
realpath($_SERVER['SCRIPT_FILENAME'])
$ _SERVER 스크립트입니다 asm0001.asm 실행하십시오 위한 웹 서버 ' [& # 39, SCRIPT_FILENAME& # 39,]' 에는 전체 경로는 처음에 호출됨 스크립트입니다 도왔으매 너회의 이네스.프퍼 할 것이다. 이 사건 () '' 릴파스 필요하지 않습니다.
$ _SERVER 콘솔에서 스크립트 실행하십시오 대한 ' [& # 39, SCRIPT_FILENAME& # 39;]' 이 포함되어 있어 현재 작업 중인 상대 경로를 통해 처음에 호출됨 스크립트입니다 dir 않으면 절대 경로 내에 스크립트입니다 변경일 작업 디렉터리를 가리키는 것으로 보인다.