how to convert pdf to jpg image format
<p>Code is written below.The output come with the images converted sucessfully but not foound on images.
It converted successfully,but the image was not generated properly in my defined folder. Any suggestion??</p>

<pre><code>&lt;?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 only &lt;b&gt;\"PDF\"&lt;/b&gt; allowed.";
        }
        else
        {
            $ImageName      = preg_replace("/\.[^.\s]{3,4}$/", "", $ImageName);
            $NewImageName = $ImageName.'-'.$RandomNum.'.'.$ImageExt;

            move_uploaded_file($_FILES["myfile"]["tmp_name"],$output_dir. $NewImageName);

            $location   = "photos/";
            $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&lt;$num;$i++)
            {
                $display .= "&lt;img src='$output_dir$RandomNum-$i.jpg' title='Page-$i' /&gt;&lt;br&gt;"; 
            }
            $message = "PDF converted to JPEG sucessfully!!";
        }
    }
}
function count_pages($pdfname) {
      $pdftext = file_get_contents($pdfname);
      $num = preg_match_all("/\/Page\W/", $pdftext, $dummy);
      return $num;
    }
$content = $message.'&lt;br /&gt;'.$display.'&lt;br&gt;&lt;form enctype="multipart/form-data" action="" method="post"&gt;
 Please choose a file: &lt;input name="myfile" type="file" /&gt;&lt;br /&gt;
 &lt;input type="submit" value="Upload" /&gt;
 &lt;/form&gt;';


echo $content;
?&gt;
</code></pre>