3

I create a pdf.php

<?php 
include("mpdf60/mpdf.php");

$url = $_GET['url'];

ob_start(); 
include($url);
$html = ob_get_clean();
$mpdf=new mPDF('utf-8', 'A3-L'); 
$mpdf->SetDisplayMode('fullpage');
$mpdf->WriteHTML($html);
$mpdf->Output();
exit;
?>

But when pass parameters exemple:

<?php

$url = 'gerencial_consad.php?mes='.$mes.'&ano='.$ano.'&menu=N';

?>

<a href="pdf.php?url=<?php echo $url; ?>">[ Gerar PDF ]</a>

The file PDF is create with the error:

Warning: include(gerencial_consad.php?mes=01): failed to open stream: Result too large in C:\wamp64\www\codforv2\pdf.php on line 7 Call Stack

Time Memory Function Location

1 0.0005 240264 {main}( ) ...\pdf.php: ( ! ) Warning: include(): Failed opening 'gerencial_consad.php?mes=01' for inclusion (include_path='.;C:\php\pear') in C:\wamp64\www\codforv2\pdf.php on line 7 Call Stack

Time Memory Function Location

1 0.0005 240264 {main}( ) ...\pdf.php:

Help me please!!!!

Thanks!

1 Answer 1

3

You don't want to include the URL, you want to download the contents of the URL with a HTTP client.

The simplest way, limited perhaps with allow_url_fopen ini setting, is to use file_get_contents function.

You need to pass the entire URL to the function:

$url = $_GET['url']; // http://example.com/
$html = file_get_contents($url);
$mpdf->WriteHTML($html);

Warning: by using unfiltered and unsanitized user input ($_GET['url'] directly), you are opening a security hole in your application. Always limit the input to content you know is safe.

You should best get only parameters for the URL from the request and combine the final URL internaly.

Sign up to request clarification or add additional context in comments.

3 Comments

I change my file pdf.php to: <?php include("mpdf60/mpdf.php"); $url = $_GET['url']; ob_start(); $html = file_get_contents($url); $html = ob_get_clean(); $mpdf=new mPDF('utf-8', 'A3-L'); $mpdf->SetDisplayMode('fullpage'); $mpdf->WriteHTML($html); $mpdf->Output(); exit; ?> But don't works See the error: Warning: file_get_contents(gerencial_consad.php?mes=01): failed to open stream: Result too large in C:\wamp64\www\codforv2\pdf.php on line 8 1 0.0013 240440 {main}( ) ...\pdf.php: 2 0.0773 16275656 file_get_contents ( ) ...\pdf.php:8
PHP Version 5.6.25 Directive = allow_url_fopen Local Value = On Master Value = On
Ok. I rebuit the code and apply base64_ecode e base64_decode. And works!! [code] <?php include("mpdf60/mpdf.php"); $url = $_GET['url']; $original = base64_decode($url); ob_start(); $html = file_get_contents($original); //$html = ob_get_clean(); $mpdf=new mPDF('utf-8', 'A4-L'); //$mpdf=new mPDF('utf-8', 'A3-L'); //$mpdf->SetDisplayMode('fullpage'); $mpdf->WriteHTML($html); $mpdf->Output(); exit; ?> [/code]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.