Why does fopen () behave like this?

I am currently working on this project, which requires me to make a function that dynamically resolves the directory name and then creates a simple .txt file in this directory.

my code is as follows: ($ destinatario - string)

     $diretorio="../messages/".$destinatario;
if (is_dir($diretorio)) {
    ;
}else{
    mkdir($diretorio);
}
$path=$diretorio."/".$data.",".$assunto.",".$remetente.".txt";
$handle=fopen($path,'w+');

fwrite($handle, $corpo);

fclose($handle);

Never think of Portuguese, but the bottom line is that it must create a .txt file using the naming conventions I have given. The funny thing is that when I do this, php creates this strange file whose file name is "09/01/2010 04" (without the extension at all), which is the first few characters of the actual file name that I would like to create ...

edit ($ data is actually the result of calling on a date ("dmY H: i"))

+3
4

Per OP:

[$ data] - ( "d.m.Y H: i" )

:. ( , , .)



@tchen answer. , ( ? All?) * Nix , Windows.

+4

, $data . trim() .

, , '\ r' '\n'.

+1

, , if :

if (!is_dir($diretorio)) {
    mkdir($diretorio);
}

It will also save this empty line from a single terminator ;, I am sure that it is wrong.

0
source

Some ideas:

  • Have you tried not to use commas in the file name?
  • Have you checked the return value if fopen and fwrite?

Just to try to isolate the problem

also you can simplify:

if (!is_dir($diretorio)) {
  mkdir($diretorio);
}
0
source

Source: https://habr.com/ru/post/1762599/


All Articles