I am trying to use PHP's rename
to move a file to a different folder (and also rename the file in the same step). However, rename
always returns false
. On the other hand, using a combination of copy
and unlink
works just fine. What could be causing this?
The relevant code looks like this:
if (!rename($targetpath, $backuppath)) {
// if rename fails, try with copy and delete
if (!copy($targetpath, $backuppath))
die("9\nCould not move existing file to backup");
touch($backuppath, filemtime($targetpath));
if (!unlink($targetpath))
die("9\nCould not move existing file to backup");
}
The paths would be e.g.
$targetpath: /path/to/plots/some.pdf
$backuppath: /path/to/plots/old/some.pdfX14068815860