Jump to content

Beginner problem: Trying to file_get_contents of file that force-downloads


yortzec

Recommended Posts

I am trying to get the contents of a file on an external website (the file is http://sync.in/ep/pad/export/c9ppXi1bp7/latest?format=txt), but it fails, I think because the server force-downloads the file. Is there any way to fix this or go around this?

 

I receive the following error:

 

Warning: file_get_contents(http://sync.in/ep/pad/export/c9ppXi1bp7/latest?format=txt) [function.file-get-contents]: failed to open stream: Connection refused

 

Thanks for any help,

Y

Link to comment
Share on other sites

file_get_contents() is enough. Apparently the sync.in server is refusing your connection to download the file. Or maybe your PHP configuration disallows downloading files but I think you'd get a different error message for that.

 

I just tried

echo file_get_contents("http://sync.in/ep/pad/export/c9ppXi1bp7/latest?format=txt");

and it worked for me.

Link to comment
Share on other sites

"force downloads" is a browser thing.  It is a http header sent with the response to tell the browser to initiate download.  It means absolutely nothing to server-side scripting unless you write your script to look for it and do something.  Same thing w/ browsers, actually...just that browsers ARE written to look for it and do something.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.