gpt4 book ai didi

PHP file_put_contents 带有绝对路径?

转载 作者:行者123 更新时间:2023-12-03 00:10:22 26 4
gpt4 key购买 nike

我使用 Wordpress 和 PHP 以及函数 file_put_contents()。 WordPress 文件结构可能因用户而异。

我需要这样调用它:

file_put_contents(TEMPLATEPATH . '/ps_logo2.png');

或类似的事情:

file_put_contents('C:\wamp\www\domain\modehallen.se/wp-content/uploads/images/ps_logo2.png');

上面的情况是本地主机上的绝对路径(这就是为什么它是 C:)。我需要路径或其他方式来确保文件放置在正确的位置。

这是如何完成的?

最佳答案

怎么样:

file_put_contents($_SERVER['DOCUMENT_ROOT']."path/to/user/wordpress/account/".TEMPLATEPATH.'/ps_logo2.png');

编辑

$_SERVER['SCRIPT_NAME'] 给出当前正在处理的脚本的路径。

关于PHP file_put_contents 带有绝对路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5444747/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com