开发者

File modified date/time changes when uploaded via FTP

开发者 https://www.devze.com 2023-01-03 01:44 出处:网络
FTP/PHP question here. On one of my pages I load .txt files from a directory. Pretty simple. I also display the modified date of the text file using this:

FTP/PHP question here. On one of my pages I load .txt files from a directory. Pretty simple. I also display the modified date of the text file using this:

da开发者_运维问答te('m/d/Y', filemtime($file));

This works fine on my WAMP server but when I upload the files via FTP, the modified date is changed to when they were uploaded. I'm currently hosting on a free hosting provider (freehostia to be exact). Is there any way to keep the modified date/time from changing when it's uploaded? Or is there perhaps an alternative way to go about this? Any ideas are appreciated.


There's an option in most FTP clients to preserve modification times of files when uploaded -- hunt around your options for it. I know FileZilla and WinSCP at least support this. Only some FTP servers will acknowledge this, though.

If your server doesn't support it, you'll have to come up with some other method to do what you're doing. In the long run I'd recommend finding some other way anyway, because typically the last modified time isn't a "critical" piece of data that is always kept in sync across backups, file transfers, etc. If the date is stored (for example) in the file, you'll never have to worry about losing it.


FileZilla retains the modified date but the created date is set to the date of transfer. You might find zipping all the files before you upload and then unzipping will preserve everything. My own test showed however that the created date on folders was reset. Plain files stayed the way they were. -Paul-


When I want to change the file modification time, I use an FTP client on the console. Log on to a remote FTP ftp ftp.dic.com

  • cd commands go to the correct directory
  • SITE command to move the extended command mode
  • UTIME somefile.txt 20050101123000 20050101123000 20050101123000 UTC

change the access time, modification time, it's time to create a directory on 2005-01-01 12:30:00 somefile.txt

Complete example:

site UTIME somefile.txt 20150331122000 20150331122000 20150331122000 UTC

0

精彩评论

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