PHP file_put_contents with absolute path?
I use Wordpress and PHP and the function file_put_contents().开发者_JS百科 Wordpress file structure can look different depending on the user.
I need to call it like this:
file_put_contents(TEMPLATEPATH . '/ps_logo2.png');
or the same thing like this:
file_put_contents('C:\wamp\www\domain\modehallen.se/wp-content/uploads/images/ps_logo2.png');
The case above is the absolute path on localhost (that's why it's C:). I need the path or some other way to make sure the file is put in the right place.
How is this done?
How about something like:
file_put_contents($_SERVER['DOCUMENT_ROOT']."path/to/user/wordpress/account/".TEMPLATEPATH.'/ps_logo2.png');
edit
$_SERVER['SCRIPT_NAME']
gives the path to the script currently being processed.
realpath()
will tell you if it is a valid path in the filesystem. To test if the path is actually in a given 'sandbox' path, see the answers to this question I asked here recently.
精彩评论