File_put_contents question

I want to create an html page using the php code form c:\www\test\script\new\creat_html.php to c:\www\test\html\index.html .

Now in c:\www\test\script\new\creat_html.php how to set the path?

I use dirname(__FILE__) , but it just gets the parent path. How? Thanks.

 file_put_contents( dirname(__FILE__) . '/index.html', $html); 
+6
source share
2 answers

dirname(__FILE__) will return:
c:\www\test\script\new\
you need c:\www\test\html\index.html
so you need up to two levels, you can do this with the .. symbol in the path:
c:\www\test\script\new\..\..\ = c:\www\test\
Now you can add the necessary part of the path:
dirname(__FILE__).'../../html/index.html'

+7
source
 file_put_contents("../../index.html", $html); 

simple - simple

EDIT: you need to access creat_html.php directly or this solution will not work!

+5
source

Source: https://habr.com/ru/post/890831/


All Articles