我想用PHP代码表单c:\www\test\script\new\creat_html.php
来创建html页面c:\www\test\html\index.html
.
现在c:\www\test\script\new\creat_html.php
我该如何设置路径?
我用dirname(__FILE__)
,但它只是得到父路径.如何?谢谢.
file_put_contents( dirname(__FILE__) . '/index.html', $html);
Run Code Online (Sandbox Code Playgroud)
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'
file_put_contents("../../index.html", $html);
Run Code Online (Sandbox Code Playgroud)
简单 - 简单
编辑:您必须直接访问creat_html.php,否则此解决方案将无法正常工作!
归档时间: |
|
查看次数: |
24032 次 |
最近记录: |