Skip to content Skip to sidebar Skip to footer

Is_file Fails On Passed Pdf File

I am writing some code to take a page, turn it into a pdf, and email the pdf. I am using html2canvas and jsPDF to generate the pdf. I then send the pdf to a php script to process i

Solution 1:

The problem with php side is that in function MailWithAttachment you are expecting a little bit different type of data for files parameter.

$file = $_POST['data']; is actually not a file, but a base64 encoded string(btoa(doc.output())). So what you actually want to do is something like this(following the signature of MailWithAttachment function).

change this:

//attachment files path array
$file = $_POST['data'];

to something like this:

//attachment file encoded$files = array();
$file = $_POST['data'];
$filePath = '/tmp/foo.pdf';
// actually here you can do whatever you want. you just need to save file on disk, at least for request context. I think creating file in memory also should work.
file_put_contents($filePath, base64_decode($file));
$files[] = $filePath;
...
// pay attention $file is changed to $files here
MailWithAttachment(...,$files);
...

Post a Comment for "Is_file Fails On Passed Pdf File"