> Why move the temporary file when it is already a temporary file, right?

If you don't want to have to write the file again with a copy?

On Sat, May 6, 2023 at 1:56 PM Hans Krentel <hanskren...@yahoo.de> wrote:

>
>
>
> On Saturday 29 April 2023 09:32:42 (+02:00), Dan Liebner wrote:
>
>  > Are there any inherent problems with moving a file created with
> tmpfile()?
>  >
>  > In practice, it seems that it can be done and the file will not be
> deleted
>  > after being moved and the file handle closed.
>
> yes, not that it would be inherently wrong to do it that way, it is that
> tmpfile() already offers the file handle, so you can rewind() and put the
> contents in your destination file:
>
>
> $destinationPath = tempnam(__DIR__, '.destination.');
> $tempHandle = tmpfile();
>
> # ... operate on $tempHandle ...
> fwrite($tempHandle, "hello world\n");
>
> rewind($tempHandle);
> $result = file_put_contents($destinationPath, $tempHandle);
> fclose($tempHandle);
>
>
> Why move the temporary file when it is already a temporary file, right?
>
> -- hakre
>

Reply via email to