cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

Re: Downloading a file instead of the web page

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Tue, 26 Mar 2002 00:28:56 +0100 (MET)

On Mon, 25 Mar 2002, Peter Bowyer wrote:

> I am trying to use curl with PHP to download a file from a web site. The
> problem is that the file is downloaded from the browser rather than echoed
> to the screen, and curl is saving the webpage displayed instead of the file
> to my server.

I don't fully comprehend this. "the file is downloaded from the browser" ?
What does that mean?

> The file to be saved sends the following headers:
>
> Content-Type: application/text; name="phpa.keys"
> Content-Disposition: inline; filename="phpa.keys"
>
> So, is there any way to get curl to snatch this file instead of the web
> page?

If you get a HTML page back instead of the actual file you thought you'd get,
it might very well be because you did something wrong in your post.

When I try that form manually, I get a "application/text" thing back. You
should get that too when you post with curl.

> $domains = "www.test.com\ntest.com\nfoobar";
> ###print "These are the domains you are sending:\n\n$domains\n\n";
> $submit = array('formname' => 'register2',
> 'domain2' => $domains
> );

I don't know if this is relevant or not here, but line separators should be
done with CRLF in posts.

> curl_setopt($ch, CURLOPT_POST, 1);
> curl_setopt($ch, CURLOPT_POSTFIELDS, $submit);
> curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
> // curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

It might have to do with you not following locations. And it could be a
cookie issue as well.

> Any advice gratefully received.

Check the headers that are returned. They may reveal interesting things.

Another good idea is to run a network analyzing program that can display what
your favourite browser sends to the server, as then it is easier for you to
make sure you send the same things.

-- 
    Daniel Stenberg -- curl groks URLs -- http://curl.haxx.se/
Received on 2002-03-26