php - save multiple pdf files using dompdf in loop not working -
i using dompdf. want save multiple pdf files server. below code through im trying accomplish task. im getting orders in 1 pdf file. means 1 pdf file generated although loop executing more once. , data appending in same pdf file , data correct.
$sel_orders = "select * tbl_orders `user_id`=$user_id , `mail`='pending' group order_num"; $order_res = mysql_query($sel_orders); $sum = mysql_num_rows($order_res); $dir = dirname(__file__); require_once($dir.'/dompdf/dompdf_config.inc.php'); if($sum > 0) { while($row1 = mysql_fetch_array($order_res)) { $order_num = $row1['order_num']; // test-123 $post = new stdclass; ob_start(); include($dir.'/pdf.php'); $pdf_html = ob_get_contents(); ob_end_clean(); $dompdf = new dompdf(); // create new instance of dompdf $dompdf->load_html($pdf_html); // load html $dompdf->render(); // parse html, convert pdf $pdf_content = $dompdf->output(); // put contents of pdf variable later error_reporting(e_error | e_parse); $file_to_save = '"http://www.exampe.com/test/orders/$order_num.pdf"'; file_put_contents($file_to_save, $dompdf->output()); } }
in pdf.php file have html code printed in pdf created. each time control enters loop want create 1 separate pdf. tried solution below link doesnt work me. plz point me im doing wrong?? if further info needed plz let me know. thanks!
i doubt web site going let save file using url, either way easier use relative path , filename, if site code running.
start using real , valid filename output. save document $pdf_content
, dont use variable.
$pdf_content = $dompdf->output(); // make valid directory , filename site // check web server account has correct privilages write $file_to_save = "/test/orders/$order_num.pdf"; file_put_contents($file_to_save, $pdf_content);
Comments
Post a Comment