gpt4 book ai didi

php - file_put_contents 路径问题

转载 作者:可可西里 更新时间:2023-11-01 12:31:33 25 4
gpt4 key购买 nike

我想使用 php 代码形式 c:\www\test\script\new\creat_html.phpc:\www\test\html\index.html 创建 html 页面

现在在 c:\www\test\script\new\creat_html.php 中如何设置路径?

我使用 dirname(__FILE__),但它只是获取父路径。如何?谢谢。

file_put_contents( dirname(__FILE__) . '/index.html', $html);

最佳答案

dirname(__FILE__) 将返回:
c:\www\test\script\new\
你需要c:\www\test\html\index.html
所以你最多需要 2 个级别,你可以在路径中使用 .. 符号来完成:
c:\www\test\script\new\..\..\ = c:\www\test\
现在您可以添加必要的路径部分:
dirname(__FILE__).'../../html/index.html'

关于php - file_put_contents 路径问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6399349/

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