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'); 
?>
