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

curl-and-php

Re: script that renders a download

From: Darko Luketic <info_at_icod.de>
Date: Tue, 22 Aug 2006 13:11:35 +0200

i don't know what you mean by "squirrel it away" , probably send.
but if you just want to save it on your server and then send it to the client,
why don't you just use something like
<?php
$destfilename = "/home/www/mysite/demo/tests/testcurl.pdf";
$file = file_get_contents("http://remoteurl");

$fp = fopen($destfilename,'w');
fwrite($fp,$file);
fclose($fp);

header("Content-type : application/pdf");
header("Content-Length: " . filesize($destfilename));
print($file);
?>

On Mon, 21 Aug 2006 10:42:17 -0700
"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.
>
> $ch =
> curl_init("http://www.remotesite.com/generatepdf.php?url=www.myurl.com");
> curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
> //curl_setopt($ch,CURLOPT_HEADER, TRUE);
> curl_setopt($ch,CURLOPT_BINARYTRANSFER, TRUE); //just guessing
> $fh = fopen("/home/www/mysite/demo/tests/testcurl.pdf",'w');
> curl_setopt($ch,CURLOPT_FILE, $fh);
> $data=curl_exec($ch);
> print_r(curl_getinfo($ch));
> curl_close($ch);
> unset($ch);
> echo $data;
>
>
> If you call the remote URL directly it sends you a PDF.
>
> When I had the HEADER option set it wrote the header to testcurl.pdf
> If not it wrote a blank line.
> I want the actual PDF file to go to testcurl.pdf. How can I reference
> it! People wouldn't keep asking this question if it was so obvious how
> to do it!! Please tell me how to fix this script. I have been blind
> guessing for the pass half hour. It would probably make a nice edition
> to your examples too.
>
>
> Thankyou
>
>
>
>
> _______________________________________________
> http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2006-08-22