Signatur
rename(string $from, string $to, ?resource $context = null): bool
Beschreibung
Der beste Weg für atomare Datei-Updates: schreibe in temporäre Datei, dann rename(). Kein halbfertiger Zustand mehr sichtbar.
Parameter
| Name | Typ | Default | Beschreibung |
|---|---|---|---|
| $from Pflicht | string | — | Alter Pfad. |
| $to Pflicht | string | — | Neuer Pfad. |
| $context | resource|null | null | Context. |
Rückgabewert
Typ
bool
Beschreibung
true bei Erfolg.
Beispiele
Atomarer Schreib-Trick
<?php
$tmp = $target . '.tmp';
file_put_contents($tmp, $data);
rename($tmp, $target); // atomar