Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permission denied #23

Open
OM-Tecnologia opened this issue Jun 20, 2024 · 3 comments
Open

Permission denied #23

OM-Tecnologia opened this issue Jun 20, 2024 · 3 comments

Comments

@OM-Tecnologia
Copy link

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
Copy link
Member

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
Copy link
Author

Hello, thanks for your answer.

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

@MaximilianKresse
Copy link
Member

MaximilianKresse commented Jun 24, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants