Re: Moving a tmpfile()?
| From: | Hans Henrik Bergan | Date: | Sun, 30 Apr 2023 07:55:58 +0000 |
| Subject: | Re: Moving a tmpfile()? | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-120164@lists.php.net to get a copy of this message | ||
@Robert I know windows has problems with moving files that are opened
by other processes,
BUT this still works fine on Windows 10 running on NTFS:
<?php
$h = tmpfile();
$path = stream_get_meta_data($h)['uri'];
var_dump(rename($path, __DIR__.'/test.f'));
?>
rename returns true and the file really is moved (and the file is no
longer automatically deleted - i suspect PHP's tmpfile() try to delete
the original path on cleanup, and don't keep track of renames/movings)
On Sat, 29 Apr 2023 at 14:56, Robert Landers <landers.robert@gmail.com> wrote:
>
> On Sat, Apr 29, 2023 at 9:33 AM Dan Liebner <dliebner@gmail.com> 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.
> >
> > Thanks,
> > Dan
>
> I suspect it depends on the OS. For example, in Linux, you can delete
> a file you are writing to without issues, but you cannot in Windows.
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: https://www.php.net/unsub.php
>