Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

file_put_contents path question

Tags:

php

filepath

I want to create html page using 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 do I set the path?

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

file_put_contents( dirname(__FILE__) . '/index.html', $html);
like image 267
fish man Avatar asked Jun 18 '11 22:06

fish man


2 Answers

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

like image 157
OZ_ Avatar answered Sep 27 '22 20:09

OZ_


file_put_contents("../../index.html", $html);

easy - simple

EDIT: You have to access creat_html.php directly, or this solution won't work !

like image 27
genesis Avatar answered Sep 27 '22 21:09

genesis