PHP: move with rename fails, but combination of copy and unlink works -


I use PHP's rename to move one file to a different folder Trying to file in one step) However, rename always false returns. On the other hand, using a combination of copy and unlink works just fine, what could be the reason for this?

The relevant code looks like this:

  (Rename ($ targetpath, $ backuppath)) {// If the name change fails, try Copy and delete with copy (copy ($ target path, $ backpack)) ("9 \ n can not move existing file back in backup"); Touch ($ backpack, filetime ($ target path)); If (! Unlink ($ targetpath)) dies ("9 \ n existing file can not be transferred to backup"); }  

The path will be for example

  $ targetpath: /path/to/plots/some.pdf $ backuppath: / path / to / plots / Start by checking the error:  
  Print_r (error_get_last ());  

Which php are you using? On older versions, rename works only when both the source and destination are on the same file system

Rename on some systems will also fail if you have an open file descriptor for the file.

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -