I have the code below and I want to upload generated pdf to cloudinary but stuck.
My current code is like this:
$pdf = new FPDI();
$pdf->setSourceFile("https://testwebsite.com/test.pdf");
$page= $pdf->importPage(1);
$pdf->addPage();
$pdf->useTemplate($page);
$output = $pdf->Output('newfile.pdf', 'S');
$uploadedLogoFileUrl = Cloudinary::uploadFile($output)->getSecurePath();
The above shows the pdf in browser and when I use Cloudinary::uploadFile($pdf->Output())->getSecurePath()
only, cloudinary sees it as null byte value.
You can try it with the Cloudinary/Uploader
$pdf = new FPDI();
$pdf->setSourceFile("https://testwebsite.com/test.pdf");
$page= $pdf->importPage(1);
$pdf->addPage();
$pdf->useTemplate($page);
$tempFile = tempnam(sys_get_temp_dir(), 'generated_pdf');
$pdf->Output($tempFile, 'F');
try {
$cloudinaryResponse = Uploader::upload($tempFile, array(
"resource_type" => "auto",
"folder" => "pdfs"
));
$pdfUrl = $cloudinaryResponse['secure_url'];
echo "PDF uploaded successfully. PDF URL: " . $pdfUrl;
} catch (\Exception $e) {
echo "Error uploading PDF: " . $e->getMessage();
}
Just make sure you have the correct path to the FPDI library and the Cloudinary PHP SDK in your project, and ensure that your Cloudinary credentials and folder settings are correct in the upload function. Hope this helps.