PHP copy file without changing last modified date

According to a comment in the PHP manual about Copy (): http://php.net/manual/en/function.copy.php

Copy () will change the last modified date of the target file.

Is there a way to copy a file without updating the last modified date?

+8
source share
4 answers

Can I copy a file without updating the last modified date?

Maybe not, but you can use touch() to change the time to the desired value.

+11
source
 function copydt($pathSource, $pathDest) { // copy(), same modification-time copy($pathSource, $pathDest) or return FALSE; $dt = filemtime($pathSource); if ($dt === FALSE) return FALSE; return touch($pathDest, $dt); } 
+13
source

you can use filemtime () to get the last modified date, then tap () to change the last modified date / time

+3
source

The sentence from the PHP documentation documentation for "copy" suggests using the exec () command to call "xcopy" to execute the copy. This worked for me, but I like the copy / touch solution more. I am comparing mtimes already, so there was no performance delay for this. I have not tried it, but I assume that "cp" will work on * nix.

+2
source

All Articles