How fopen can work?

$fname = tempnam() . getmypid();
$f = fopen($fname, "w");

this is the name of the file, but
- Process ID, as it was then
fopen($fname, "w");
may not work if 1 parameter, you specify the file name or URL, and $fname is the name with ID?
April 3rd 20 at 18:51
2 answers
April 3rd 20 at 18:53
Tempname is not a magic file name, which someone kindly created for you.
This is the line that generated random file name in system temporary directory (and, presumably, the program checks for the existence of such already - not sure here).
You don't have to use that file actually doesn't exist yet, it creates just fopen.
Another thing that is changing is the name that you reset the validation for uniqueness - and it is already your responsibility to ensure that there is no such file in the temporary directory, and then that could be bad...
on the contrary, the author feared that the Tempname can generate non-unique name, and with getmypid() everything will be OK(if I'm not mistaken). - Kim commented on April 3rd 20 at 18:56
April 3rd 20 at 18:55

w - Opens the file for writing only; places the pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.
Type error: logical

The most serious type of error - otha commented on April 3rd 20 at 18:58

Find more questions by tags PHP