开发者

PHP copy file without changing the last modified date

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

The copy() will cha开发者_高级运维nge the last modified date of the destination file.

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


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);
}


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

Probably not, but you can use touch() to modify the time back to your desired value.


you can use filemtime() to get last modified date and then touch() for modifying last modified date/time


A suggestion from the PHP documentation annotations for 'copy' suggests using the exec() command to invoke 'xcopy' to perform the copy. This worked for me, but I like the copy/touch solution better. I am comparing mtimes already, so no performance lag added for that. I haven't tried it, but I assume that 'cp' will work on *nix.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜