如何使用 PHP 获取在另一台服务器上生成的文件名
How to get filename which generated on another server with PHP
第一个服务器有代码生成文件并给它新的名字。
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')
除了使用 file_get_contents()
,您还可以使用 curl
来获取 HTTP 响应的 header。
这是一个例子:
<?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
数据。
第一个服务器有代码生成文件并给它新的名字。
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')
除了使用 file_get_contents()
,您还可以使用 curl
来获取 HTTP 响应的 header。
这是一个例子:
<?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
数据。