Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP copy file without changing the last modified date

Tags:

date

file

php

copy

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

The copy() will change the last modified date of the destination file.

Is there a way that a file can be copied without updating the last modified date??

like image 700
LazNiko Avatar asked Feb 04 '11 13:02

LazNiko


1 Answers

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);
}
like image 90
Bob Stein Avatar answered Nov 12 '22 19:11

Bob Stein