Can't create file via PHP... Is there a restriction on this?

$txt = htmlspecialchars($_GET[value"]);

if (!empty($txt))
    $myfile = file_put_contents('test_file.txt', $txt.PHP_EOL , FILE_APPEND | LOCK_EX);

So the above code does not create test_file.txt
Is there a permission I can change? I have free webhosting setup.

Thanks!

i too had some php file issues, was reading a file not writing but im assuming its the same problem, I had to prefix the server path to the file name with

$_SERVER["DOCUMENT_ROOT"]
2 Likes

It’s not working because you are missing a double quote in this line. When coding in PHP, it is best to use a IDE that color-codes your code.

When you pasted your code here, you can tell that the color is off, right? That means you are missing a quote, end tag, bracket, curly bracket, or comma.

3 Likes

This was it thank you!

@Greenreader9 good catch, I actually rewrote this here instead of copy and pasting - silly of me :sweat_smile: my original code had both "

oo well spotting, i missed it too!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.