-1

I've been using file_put_contents in order to create txt files inside a specified folder that has write permissions:

file_put_contents($dir.$file.'.txt', $content);

Editing my code, I made a mistake: I wrote $dir = '/../../xxx/yyy/'; (that actually doesn't exist) instead of $dir = '../xxx/yyy/'; (right directory).

Obviously, no file has been created (all other folders are read-only), but I didn't get any error message about it.

Why?

P.S.: I get other error messages on the same PHP page, but not the above one.

j08691
  • 204,283
  • 31
  • 260
  • 272
AbsoluteBeginner
  • 2,160
  • 3
  • 11
  • 21

2 Answers2

1

From the docs:

"This function returns the number of bytes that were written to the file, or FALSE on failure"

https://www.php.net/manual/en/function.file-put-contents.php

I.e use something like $result = file_put_contents($dir.$file.'.txt', $content);

And check if it's true or not

micke
  • 117
  • 1
  • 6
-2

try this

$dir = '../xxx/yyy/';
$handle = fopen($dir,'w');
fwrite($dir, "write some here");
fclose($dir);
  • 2
    Please don't post only code as answer, but also provide an explanation what your code does and how it solves the problem of the question. Answers with an explanation are usually more helpful and of better quality, and are more likely to attract upvotes. – Mark Rotteveel Aug 30 '20 at 17:25