【问题标题】:How to get filename which generated on another server with PHP如何使用 PHP 获取在另一台服务器上生成的文件名
【发布时间】:2018-06-27 05:25:25
【问题描述】:

第一台服务器具有生成文件并为其命名的代码。

header('Content-Type: application/pdf');
header('Content-disposition: filename="i_want_get_it.pdf"');
header('Cache-Control: no-cache');
header("Content-Transfer-Encoding: binary");
readfile(ROOT.'/files/5548951235');

在另一台服务器上,我想获取文件名(代码中的 i_want_get_it.pdf)。我只能使用

获取文件内容
file_get_contents('http://some_link.com?act=getfile&id=5548951235')

【问题讨论】:

  • 请减少您的 sn-ps 中的制表符以减少水平滚动。

标签: php http-headers filenames file-transfer


【解决方案1】:

除了使用file_get_contents(),您还可以使用curl 来获取HTTP 响应的标头。

这是一个例子:

<?php

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch); 

list($header, $body) = explode("\r\n\r\n", $result, 2);
var_dump($header);

?>

您将看到Content-disposition 数据。

【讨论】:

    猜你喜欢
    • 2011-12-12
    • 1970-01-01
    • 1970-01-01
    • 2018-09-20
    • 1970-01-01
    • 1970-01-01
    • 2017-01-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多