Fopen 到远程 php 脚本

发布于 2024-10-01 07:51:41 字数 221 浏览 0 评论 0原文

我必须下载一个由 php 脚本创建的文件。
我尝试了这个:

fopen('www.example.com/download.php?key=value', 'rb');

但我仍然收到“无法打开流”错误。
我怎样才能做到这一点?如果我浏览到该网址,我会毫无问题地获取文件...

编辑:抱歉,我忘记了一段字符串:)

i have to download a file created from a php script.
i tried this:

fopen('www.example.com/download.php?key=value', 'rb');

but i stille get a "failed to open stream" error.
how can i do that? If I browse to the url i get the file without problems...

EDIT: sorry, i forgot a piece of the string :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

神回复 2024-10-08 07:51:41

我发现您的请求存在多个问题:

  1. 您需要指定打开模式。在您的情况下,只有 'r' 适用,因为您只想读取。
  2. 您需要指定协议。在你的情况下“http”。
  3. 您需要启用 URL 包装器。执行 phpinfo() 并查看 allow_url_fopen 是否设置为 On
  4. 无论如何,您可能想要 file_get_contents
  5. 您应该启用错误报告并阅读错误消息。这将帮助您更快地跟踪问题。
  6. 如果您决定使用fopen,请不要忘记fclose

示例:

$data = file_get_contents('http://www.example.com/download.php?key=value');

您还应该阅读手册中有关 fopen 的内容。

I see multiple issues with you request:

  1. You need to specify the open mode. In your case only 'r' applies because you only want to read.
  2. You need to specify the protocol. In your case "http".
  3. You need to have URL wrappers enabled. Do a phpinfo() and look if allow_url_fopen is set to On.
  4. You probably wanted file_get_contents anyway.
  5. You should enable error reporting and read the error messages. That will help you track the problem faster.
  6. Don't forget to fclose if you decide to use fopen.

Example:

$data = file_get_contents('http://www.example.com/download.php?key=value');

You should also read about fopen in the Manual.

泪痕残 2024-10-08 07:51:41

看起来您需要首先阅读 fopen 的用法,这里是一个示例用法:

fopen ("http://www.example.com/", "r");

r = read,这可能会导致您的失败。

It looks like you need to read the usage for fopen first, here is an example usage:

fopen ("http://www.example.com/", "r");

r = read, that might be causing your failure.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文