外部 URL 的 PHP readfile()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4752389/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 14:15:02  来源:igfitidea点击:

PHP readfile() of external URL

phpreadfile

提问by user583311

Can I use external URLs in readfile()?

我可以在 readfile() 中使用外部 URL 吗?

    header('Content-type: application/pdf');
    header('Content-Transfer-Encoding: binary');
    header('Content-Disposition: inline; filename="'.$file.'" ');
    //header('Content-Length: ' . filesize("http:...z/pub/".$file.'.pdf'));
    @readfile("http://...z/pub/".$file.'.pdf');

回答by Jacob Relkin

The PHP manual on readfilestates:

PHP 手册上readfile指出:

A URL can be used as a filename with this function if the fopen wrappershave been enabled. See fopen()for more details on how to specify the filename. See the Supported Protocols and Wrappersfor links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide.

如果已启用fopen 包装器,则可以将 URL 用作此函数的文件名。有关如何指定文件名的更多详细信息,请参阅fopen()。请参阅支持的协议和包装器以获取有关各种包装器具有哪些功能的信息、使用说明以及它们可能提供的任何预定义变量的信息的链接。

As an alternative you can also use file_get_contents:

作为替代方案,您还可以使用file_get_contents

echo file_get_contents("http://...z/pub/".$file.'.pdf');

回答by wajiw

Yes, according to the readfilepage:

是的,根据readfile页面:

A URL can be used as a filename with this function if the fopen_wrappershave been enabled. See fopen() for more details on how to specify the filename. See the Supported Protocols and Wrappersfor links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide.

如果 已启用fopen_wrappers,则URL 可用作此函数的文件名。有关如何指定文件名的更多详细信息,请参阅 fopen()。请参阅 支持的协议和包装器以获取有关各种包装器具有哪些功能的信息、使用说明以及它们可能提供的任何预定义变量的信息的链接。