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

curl-and-php

Re: script that renders a download

From: Kevin Carothers <kevindotcar_at_gmail.com>
Date: Mon, 21 Aug 2006 13:54:21 -0700

On 8/21/06, Colleen R. Dick <platypus_at_proaxis.com> wrote:
>
> I want to invoke a script on a remote server purpose is to generate a
> pdf file and send it to the browser. I wish to capture the pdf in the
> background and squirrel it away (since the remote site gives you no
> direct option to do that.)
>
> I searched the mailing list--surely someone else has wanted to do this!
> One similar question was brushed off by suggesting that the reader read
> the docs and examples and use the dead simple one. Another individual
> asked a similar question and was advised to "set the options" and do it.
> I have read all of the examples and I have read http://us2.php.net/curl
> It lists a s**tload of options but it doesn't tell you what they do or
> give examples. There are a bunch of functions that aren't documented.
> I just wanted you to know that *I have done my homework.* I RTFM and
> the FM is just a skoshe sketchy. Also I am using PHP 4.
>
> This is my best guess so far.
> {---}
>

 Hi Colleen,
My semi-random thoughts follow, but you'll prolly get a lot of info on
Google groups... I've done what I think you're asking for under vastly
similar environments (JSP pages and CGI)- You might already be doing what
I'm about to suggest, I just can't tell (because I don't use libCurl - just
the cmd line tool).

A method would be to set up the remote PDF file as a URL and have PHP
redirect the browser's connection from YOUR server to the remote-
BEWARE... a lot of web servers don't allow this, so if you don't have say
about the remote server's policies, you might be setting yourself up for
failure.

Given that that is prolly a dangerous proposition, you'll have to (as you
say) "squirrel' away the PDF to your web server... that's all file, but
there are issues--- deleting all the "temporary" PDF's (if they are
temporary) comes to mind.... also comes the issue of multiple requests for
the same file.

Also- I think you have to somehow tell the browser that the binary file is a
PDF with an HTTP hdr:
"Content Type: Application/*.PDF"
 (you can google the exact header info)

-And, some browsers/web servers are really picky about the file length for
Application/* files so you'll prolly have to add a
"Content Length: 123456"
HTTP header too....

And MSIE needs a "CONTENT-DISPOSITION:" header, I recollect.

-As I said earlier, you may have multi-threading things to worry about if
your web server is busy 'squirlling' away a PDF and another user makes the
same request for the same document- In similar situations I've had to
implement Perl-coded semaphores to keep multiple requests from trashing
files that were "in-progress" during download.

-PS
I don't know about PHP but in Perl, I've had to close STDOUT and re-open the
stream as Binary for the PDF to display correctly- as PDF's are pure
binary, not ASCII.

-PPS
Don't forget SOME user's don't have browser PDF reader plugins.

Hope this helps

KC

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2006-08-21