外部URL的PHP​​ readfile() [英] PHP readfile() of external URL

查看:94
本文介绍了外部URL的PHP​​ readfile()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Can I use external URLs in readfile()?

    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');

推荐答案

readfile 上的PHP手册指出:

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

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

您也可以使用file_get_contents:

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

这篇关于外部URL的PHP​​ readfile()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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