【问题标题】:Retrieve file last modified from file header using CURL使用 CURL 从文件头中检索最后修改的文件
【发布时间】:2014-02-24 10:51:57
【问题描述】:

我想知道是否可以使用 CURL 获取 csv 文件的“最后修改日期时间”。

我依靠随机更新的 CSV 文件来保持数据库表是最新的。我只想在上次表更新后文件被修改时,用 CSV 文件数据更新数据库表。

如果您知道描述此内容的文档的链接,如果您能在此处发布它们,我将不胜感激。

我做了一些搜索,但我的搜索引擎被与 html 标题相关的搜索淹没了。

【问题讨论】:

  • 使用CURLOPT_HEADER = true 的 curl 请求并解析出服务器提供的最后修改日期。
  • 嗨,Salman A,这对我来说似乎是一个很好的答案。随时将您的评论转化为答案,我会投票赞成。
  • @David.LPower 你可以看到我的回答

标签: php csv curl last-modified


【解决方案1】:

您可以使用CURLOPT_HEADER通过以下方式做到这一点

<?php
$curl = curl_init();

curl_setopt($curl, CURLOPT_URL, $url);
// Only header
curl_setopt($curl, CURLOPT_NOBODY, true);
curl_setopt($curl, CURLOPT_HEADER, true);
// Do not print anything to output
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

// get last modified date
curl_setopt($curl, CURLOPT_FILETIME, true);

$result = curl_exec($curl);
// Get info
$info = curl_getinfo($curl);

echo "Last modified time : " . date ("d-m-Y H:i:s", $info['filetime']) );
?>

【讨论】:

  • 谢谢侯赛因。这很有帮助。
猜你喜欢
  • 1970-01-01
  • 2011-11-25
  • 2023-03-17
  • 2014-03-19
  • 2011-01-19
  • 2016-08-01
  • 1970-01-01
  • 2021-04-22
  • 1970-01-01
相关资源
最近更新 更多