PHP-下载文件并保存时间戳? [英] PHP - Download file and preserve timestamp?

查看:72
本文介绍了PHP-下载文件并保存时间戳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

顾名思义,有没有一种下载文件的快速方法,但带有时间戳?

As the name suggests, is there a quick way to download a file, but bring the timestamp along?

我正在编写一个基本的缓存,其中包括(通过get_headers进行的)其他检查,以确定给定的本地文件是否与远程文件相同.

I'm writing a basic cache that, among other checks, determines (via get_headers) if a given local file is the same as it's remote counterpart.

我知道我可以file_get_contents/file_put_contents然后是touch()具有get_headers结果的文件,但是该调用正在进行另一个HTTP调用(即使它是HEAD调用),我d只想测试Last-Modified作为万不得已的方法.

I know I can file_get_contents / file_put_contents and then touch() the file with the results of get_headers, but the calling that is making another HTTP call (even if it is a HEAD call) and I'd only like to test Last-Modified as a last resort.

那么,有没有一种快速的一个HTTP调用"方式来下载文件并保留时间戳?一些远程文件位于FTP服务器上,而许多是文本文件,和/或位于Web服务器上.

So is there a quick, "one HTTP call" way to download a file and preserve the timestamp? Some remote files live on an FTP server, but many are text files, and / or live on a web server.

有人提出了一个相关的问题,但是我的问题有所不同,因为我希望获得远程修改的日期而不必打第二个电话,这是基于copy()的答案所建议的

Someone suggested a related question, but my question differs, in that I'm looking to get the remote modified date without having to make a second call, which the copy() based answer suggests

$http_response_header似乎可以解决问题,如下所示.

$http_response_header seems to do the trick, as suggested below.

推荐答案

您可以从Last-Modified rel ="nofollow"> $http_response_header 并使用它来触摸文件.

You can get cached Last-Modified from $http_response_header and use it to touch the file.

要完全自动化它显然是不可能的,因为流无法知道您要将其存储在何处.

To automate it completely is obviously not possible as the stream cannot know where are you going to store it.

这篇关于PHP-下载文件并保存时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆