Can’t write pdf file to upload directory using FPDF

PHP Warning:  file_put_contents(http://lendersmatch.ca/wp-content/uploads/deals/deal1.pdf): failed to open stream: HTTP wrapper does not support writeable connections in /home/t21jv08zz60b/public_html/wp-content/plugins/mortgage/fpdf181/fpdf.php on line 1023 
[27-Jan-2018 11:24:20 UTC] PHP Fatal error:  Uncaught Exception: FPDF error: Unable to create output file: http://lendersmatch.ca/wp-content/uploads/deals/deal1.pdf in

My Code:

$filename=$upload_path.'deals/deal'.$page->id.'.pdf';
ob_clean();
$pdf->Output('F',$filename);

FPDF:

if(!file_put_contents($name,$this->buffer))
    $this->Error('Unable to create output file: '.$name);
    break;

2 Answers
2

$name apparently contains a URL. That won’t work. Set it to a local path, as you did with $filename:

    $upload_dir = wp_upload_dir();
    $filename = $upload_dir["basedir"] . '/deals/deal' . $page->id . '.pdf';

Leave a Comment