0

On my local server it's running fine but on live it's giving error like this:- mpdf error : Fatal error: Uncaught Mpdf\MpdfException: Data has already been sent to output, unable to output PDF Please tell me

$randnm=rand();
mkdir($randnm);
if(isset($_POST['submit'])){
    //move_uploaded_file();
    foreach($_FILES['doc']['name'] as $key=>$val){
        $rand=rand('11111111','99999999');
        $file=$rand.'_'.$val;
        move_uploaded_file($_FILES['doc']['tmp_name'][$key],"$randnm/".$file);
        //insert into table(image) values('$file');
    }
}
$dir_path = "$randnm/";

$extensions_array = array('jpg','png','jpeg');

if(is_dir($dir_path))
{
    $files = scandir($dir_path);
    
    for($i = 0; $i < count($files); $i++)
    {
        if($files[$i] !='.' && $files[$i] !='..')
        {
            // get file name
            echo "File Name -> $files[$i]<br>";
            
            // get file extension
            $file = pathinfo($files[$i]);
            $extension = $file['extension'];
            echo "File Extension-> $extension<br>";
            
           // check file extension
            if(in_array($extension, $extensions_array))
            {
            // show image
            $string .="<style>.boi{
                margin-top: 40px;
            }</style>
            <div class='boi'><img src='$dir_path$files[$i]'></div>";
            
        }

        }
    }
}
require_once __DIR__ . '/vendor/autoload.php'; 
$mpdf = new \Mpdf\Mpdf();
$mpdf->WriteHTML("$string");
$mpdf->Output('filename.pdf','I'); 

?>
  • My guess its the server configuration, fix it. The error class is perhaps this one: https://stackoverflow.com/a/12770075/367456 – hakre Jun 26 '21 at 10:45
  • No sir it's the error of mpdf I have checked it again and again – Sudhanshu Singh Jun 26 '21 at 12:43
  • Sure it is. Comment was about the _error class_ that is type of the kind of error situation in context of the error MPDF communicates to you. It just says that MPDF can't work on that server. Fix the configuration on the server or try a different server. The error message won't go away only you wish it so. Nevertheless, lets keep hoping for the best and have a fine day Sir! – hakre Jun 26 '21 at 13:51
  • I have used 3 servers 2 free server one paid server. I don't know what to configure on that server every thing is just default. – Sudhanshu Singh Jun 26 '21 at 14:44
  • True, with that many servers to trial and error with, maybe it might be the mPDF configuration on each of these servers, just effectively inefficient on these hosts. Maybe a study of the mPDF Manual sheds some light - just in case you haven't done it yet. Let's keep hoping for the best and the true path of wisdom and happiness to keep walking on with this very fine day Sir! – hakre Jun 26 '21 at 15:05
  • `Data has already been sent to output` definitely sounds like what @hakre mentioned in their first comment. Maybe you simply have some unexpected output. Try to wrap everything before the `->Output()` line betwen `ob_start()` and `ob_end_clean()` to catch and remove any of that. – Andrea Olivato Jun 27 '21 at 01:04

0 Answers0