I am writing a test to count the number of pages in PDFs stored in a folder on a server. I have been able to get it to work on my local machine, I am unable to get it to work on a remote file.
This is my code that works on local files:
require_once 'C:\..\application\libraries\fpdi\fpdf.php';
require_once 'C:\..\application\libraries\fpdi\fpdi.php';
$pathToFile = 'C:\Users\..\Desktop\filename.pdf';
$pdf = new FPDI();
$pageCount = $pdf->setSourceFile($pathToFile);
echo $pageCount;
But if I change the $pathToFile to a link on a remote server, I get an error message.
I tried this:
$pdfname = 'http://../filename.pdf';
$pdftext = file_get_contents($pdfname);
$num = preg_match_all('/\/Page\W/', $pdftext, $dummy);
echo 'Num: ' . $num;
But again, when I use a local file, it works fine, but the remote file gives me an error (failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden).
From searching online, it seems like that is a common error and I've seen code to use curl, but it makes no sense to me and I can't get it to work either. I saw code to use pdfinfo, but the link in that post is going to another site.
I don't want to have to download anything, so using something like Imagick is not an option either.
All I'm looking for is a simple page number from a file on a remote server. Any help would be much appreciated.