开发者

Fopen to a remote php script

开发者 https://www.devze.com 2023-01-23 11:36 出处:网络
i have to download a file created from a php script. i tried this: 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 sti开发者_如何学JAVAlle 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 :)


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号