GetSimple Support Forum

Full Version: write to file doesn't like absolute path?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm curious and maybe I've just missed something but when I try to use get_theme_url as part of the file path I can't write to file, however when I use a relative path then all works fine.

It's Friday, it been a long week so maybe I'm just missing something stupid. Just wondered if anyone had an idea.

Absolute path  - Used within a file in the theme folder:
Code:
$dataStr = "testing 123";

$fpath = get_theme_url(false)."data33.txt";
                           
file_put_contents($fpath,$dataStr);

And yet if I use the relative path without including the function 'get_theme_url()', all works fine.

Code:
file_put_contents("theme/helpdesks/data33.txt",$dataStr);
get_theme_url(false) does not return a filepath, but an URL (http://....)

You have to use GSTHEMESPATH (and optionally global var $TEMPLATE for theme folder), e.g.:
Code:
<?php
global $TEMPLATE;
echo 'Theme filepath: ', GSTHEMESPATH.$TEMPLATE;
?>
Superb.

Strange that I can use get_theme_url to read a file from a directory but it doesn't work when writing.
I'll use the method you suggested from now on

Thanks Carlos,
much appreciated
You can read files both from filepaths and URLs with file_get_contents(), but file_put_contents() can only write to filepaths.
Thanks again