Re: Moving a tmpfile()?
| From: | Hans Krentel via internals | Date: | Sat, 06 May 2023 17:56:35 +0000 |
| Subject: | Re: Moving a tmpfile()? | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-120206@lists.php.net to get a copy of this message | ||
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