Setasign / fpdi-protection

A FPDI compatible and enhanced version of the FPDF_Protection script.
MIT License
30 stars 13 forks source link

Permission denied #23

Open OM-Tecnologia opened 1 month ago

OM-Tecnologia commented 1 month ago

I don't know what else i need to do, i already gave the permission (but i think it's not even needed)

failed to open stream: Permission denied in line /Includes/fpdi/fpdf.php on line 1046 FPDF error: Unable to create output file: book_protected.pdf fpdf.php line 1046: $f=fopen($name,'wb');

My code:

function pdfEncrypt ($origFile, $password, $destFile){

    $pdf =& new FPDI_Protection();
    // set the format of the destinaton file, in our case 6×9 inch
    $pdf->FPDF('P', 'in', array('6','9'));

    //calculate the number of pages from the original document
    $pagecount = $pdf->setSourceFile($origFile);

    // copy all pages from the old unprotected pdf in the new one
    for ($loop = 1; $loop <= $pagecount; $loop++) {
        $tplidx = $pdf->importPage($loop);
        $pdf->addPage();
        $pdf->useTemplate($tplidx);
    }

    // protect the new pdf file, and allow no printing, copy etc and leave only reading allowed
    $pdf->SetProtection(array(),$password);
    $pdf->Output($destFile, 'F');

    return $destFile;
}

Did i miss something?

JanSlabon commented 1 month ago

As you can see the error is raised because PHP has no permissions to open a file handle at the path given in $destFile. It is simply up to you to pass a path with the correct permissions. So this is not an issue in FPDF or FPDI but you can also trigger that problem in your own scope by simply calling:

$fh = fopen($destFile, 'wb');
OM-Tecnologia commented 4 weeks ago

Hello, thanks for your answer.

I did the fopen in the same scope and it works.

MaximilianKresse commented 4 weeks ago

Mhh ok strange. @JanSlabon's line from above may not trigger an error immediately but if the result $fh is FALSE it also failed. Have you checked against the result?