-2

How to use "CURL" to call external URL since the url_fopen is disabled for security reasons. I want to open a pdf file. For security reason url_fopen function is disabled. So anyone can help me?

function Header()
{
 $this->SetY(20);
 $this->Image("images/logo-s.jpg", 120,0,80,20, "JPG", "www.example.com");
 $this->Ln(4);
}
Jazz
  • 53
  • 2
  • 3
  • 10

2 Answers2

1

There are lots of answers for connecting, downloading or saving something to a URL by CURL function, but even if the CURL be disabled in your server you can still use stream_context_create, check this question

To do it with CURL try

$url  = 'http://www.example.com/images/logo-s.jpg';
$path = '/path/to/images/logo-s.jpg';

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);
file_put_contents($path, $data); // to save it somewhere
Community
  • 1
  • 1
Javad
  • 4,339
  • 3
  • 21
  • 36
  • I am getting error like this 'FPDF error: Missing or incorrect image file: http://www.banyantreebank.com/images/logo-s.jpg' – Jazz Mar 08 '14 at 07:20
  • The link you provided has an extra apostrophe; I removed it and the image was opened [http://www.banyantreebank.com/images/logo-s.jpg](http://www.banyantreebank.com/images/logo-s.jpg) – Javad Mar 08 '14 at 17:01
0

First initialize a curl handler with:

$curl_handler = curl_init("http://www.linktomypdf.com/");

If you need to read it into a file:

$fp = fopen("mypdf.pdf", "w");

Now use curl_setopt() to set the option for curl_handler:

curl_setopt($curl_handler, CURLOPT_FILE, $fp);

First parameter is always curl_handler, second is which option you want to set , third is the value you want to set. So this call set CURLOPT_FILE to be $fp. There are list of options you can find it here:

https://php.net/manual/en/function.curl-setopt.php

To make it easy to read the code:

$curl_handler = curl_init("http://www.linktomypdf.com/");
$fp = fopen("mypdf.pdf", "w");
curl_setopt($curl_handler, CURLOPT_FILE, $fp);
curl_exec($ch);   //execute curl session
curl_close($ch);  // close curl_handler
fclose($fp);      // close file
Leo
  • 335
  • 2
  • 11
  • I am getting error like this 'FPDF error: Missing or incorrect image file: banyantreebank.com/images/logo-s.jpg'; – Jazz Mar 08 '14 at 07:21
  • I have no idea what is that error but I think you can find the answer here: http://stackoverflow.com/questions/3177716/fpdf-error-missing-or-incorrect-image-file – Leo Mar 08 '14 at 08:12
  • i am able to see pdf content now but not able to see image. – Jazz Mar 08 '14 at 10:19