PHP - PDF Grab with URL that does not have .pdf extension

advertisements

I'm using Filepicker.io to upload PDFs to my application. I have all those URLs and now I am trying to merge some of those PDFs using the PDF Tool Kit PHP library. It was not working for me so I ran some tests using the "file_exists" on PHP and it kept returning false.

I think this has to do with the fact that the URL does not have a ".pdf" extension at the end. This is what they look like: "https://www.filepicker.io/api/file/LCvbgpqEQLGwt8bfnqc1"

Does anyone know how I can pull the PDF using PHP in order to merge those files using the PDF Toolkit Library?

Thanks!

Alain F.


file_exists doesn't work with URLs, only with local files. Instead download the file to the temp dir using the copy command.

If the file can't be downloaded, the copy command will return false.

$exists = copy('https://www.filepicker.io/api/file/LCvbgpqEQLGwt8bfnqc1', '/tmp/example.pdf');
if (!$exists) throw new Exception("PDF could not be downloaded");

Use the downloaded file in the PDF Tool Kit.