Jen*_*ell 2 php wordpress absolute-path
我使用Wordpress和PHP以及函数file_put_contents().Wordpress文件结构可能因用户而异.
我需要这样称呼它:
file_put_contents(TEMPLATEPATH . '/ps_logo2.png');
Run Code Online (Sandbox Code Playgroud)
或者像这样的事情:
file_put_contents('C:\wamp\www\domain\modehallen.se/wp-content/uploads/images/ps_logo2.png');
Run Code Online (Sandbox Code Playgroud)
上面的例子是localhost上的绝对路径(这就是为什么它是C :).我需要路径或其他方式来确保文件放在正确的位置.
这是怎么做到的?
Emm*_*uel 11
怎么样的:
file_put_contents($_SERVER['DOCUMENT_ROOT']."path/to/user/wordpress/account/".TEMPLATEPATH.'/ps_logo2.png');
Run Code Online (Sandbox Code Playgroud)
编辑
$_SERVER['SCRIPT_NAME'] 给出当前正在处理的脚本的路径.