Badger
Badger

Reputation: 487

Load pdf from external url via php

I am trying to allow a user to download a pdf of sensitive information from an API. However, the URL returned by the API is not secure as details could potentially be guessed to obtain somebody else's information. My intention is to authenticate the user and, if they pass, pass the file directly to them. At the moment, I'm using the following, however, it doesn't work as the filesize() function apparently doesn't work with an http link.

$filename = "http://api.com/person/1234/document/1234/data?key=1234&hash=1234";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);

Upvotes: 1

Views: 2334

Answers (1)

Fredster
Fredster

Reputation: 776

Try <?php echo file_get_contents("http://api.com/person/1234/document/1234/data?key=1234&hash=1234");

Upvotes: 1

Related Questions