[英]PHP file_put_contents with absolute path?
I use Wordpress and PHP and the function file_put_contents(). 我使用Wordpress和PHP以及函数file_put_contents()。 Wordpress file structure can look different depending on the user.
Wordpress文件结构可能因用户而异。
I need to call it like this: 我需要这样称呼它:
file_put_contents(TEMPLATEPATH . '/ps_logo2.png');
or the same thing like this: 或者像这样的事情:
file_put_contents('C:\wamp\www\domain\modehallen.se/wp-content/uploads/images/ps_logo2.png');
The case above is the absolute path on localhost (that's why it's C:). 上面的例子是localhost上的绝对路径(这就是为什么它是C :)。 I need the path or some other way to make sure the file is put in the right place.
我需要路径或其他方式来确保文件放在正确的位置。
How is this done? 这是怎么做到的?
How about something like: 怎么样的:
file_put_contents($_SERVER['DOCUMENT_ROOT']."path/to/user/wordpress/account/".TEMPLATEPATH.'/ps_logo2.png');
edit 编辑
$_SERVER['SCRIPT_NAME']
gives the path to the script currently being processed. $_SERVER['SCRIPT_NAME']
提供当前正在处理的脚本的路径。
realpath()
will tell you if it is a valid path in the filesystem. realpath()
会告诉您它是否是文件系统中的有效路径。 To test if the path is actually in a given 'sandbox' path, see the answers to this question I asked here recently. 要测试路径是否实际位于给定的“沙箱”路径中,请参阅我最近在此处询问的此问题的答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.