html - convert PDF to JPEG in PHP using ZEND server -
i'm using script convert pdf jpg online. when run script on zend server , upload pdf file file upload on server & show broken images on browser.
i use 1 folder , 1 index file code written.
- upload folder
- index.php file
here script running:
<html> <head> <style type="text/css"> img {border-width: 0} * {font-family:'lucida grande', sans-serif;} </style> </head> <body> <?php $message = ""; $display = ""; if($_files) { $output_dir = "uploads/"; ini_set("display_errors",1); if(isset($_files["myfile"])) { $randomnum = time(); $imagename = str_replace(' ','-',strtolower($_files['myfile']['name'])); $imagetype = $_files['myfile']['type']; //"image/png", image/jpeg etc. $imageext = substr($imagename, strrpos($imagename, '.')); $imageext = str_replace('.','',$imageext); if($imageext != "pdf") { $message = "invalid file format <b>\"pdf\"</b> allowed."; } else { $imagename = preg_replace("/\.[^.\s]{3,4}$/", "", $imagename); $newimagename = $imagename.'-'.$randomnum.'.'.$imageext; move_uploaded_file($_files["myfile"]["tmp_name"],$output_dir. $newimagename); $location = "/usr/local/bin/convert"; $name = $output_dir. $newimagename; $num = count_pages($name); $randomnum = time(); $nameto = $output_dir.$randomnum.".jpg"; $convert = $location . " " . $name . " ".$nameto; exec($convert); for($i = 0; $i<$num;$i++) { $display .= "<img src='$output_dir$randomnum-$i.jpg' title='page-$i' /><br>"; } $message = "pdf converted jpeg sucessfully!!"; } } } function count_pages($pdfname) { $pdftext = file_get_contents($pdfname); $num = preg_match_all("/\/page\w/", $pdftext, $dummy); return $num; } $content = $message.'<br />'.$display.'<br><form enctype="multipart/form-data" action="" method="post"> please choose file: <input name="myfile" type="file" /><br /> <input type="submit" value="upload" /> </form>'; echo $content; ?> </body> </html>
the broken image is:
as per asking view pdf on browser. try online pdf viewer. download , enjoy. hope use full you.
Comments
Post a Comment