title: convert pdf into jpg using exec
body: <p>I want to convert a PDF-Image to a .JPG-Image.</p>
  
  <p>I made a convert.php which i can call with the filename of the PDF file and convert it to jpg. I call this function like this: <a href="http://www.example.ch/tools/img/cache/convert.php?f=MyPdf.pdf" rel="nofollow">http://www.example.ch/tools/img/cache/convert.php?f=MyPdf.pdf</a></p>
  
  <p>this looks like this:</p>
  
  <pre><code>if ($f = @$_REQUEST['f']) {
      $f = htmlspecialchars(urldecode($f));
      $url  = 'http://www.example.ch/img/cache/'.$f;
  
  
      $file = strtolower($f);
  
      $ch = curl_init($url);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5');
  
      $data = curl_exec($ch);
  
      $retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  
      curl_close($ch);
      if ($retcode == 200) {
          file_put_contents($file, $data);
          $converted_filename = str_replace('.pdf', '.jpg', $file );
          $cmd = 'convert '.$file.' '.$converted_filename;
          exec('convert '.$file.' '.$converted_filename);
          $fp = fopen($converted_filename, 'rb');
  
          header('Content-Type: image/jpeg');
          header("Content-Length: " . filesize($converted_filename));
          fpassthru($fp);
          exit;
      } else {
          header("HTTP/1.0 404 Not Found");
      }
  
  }
  </code></pre>
  
  <p>After this is done i get an .jpg File with the size of 700KB in my folder and i can't open it because it is corrupted. And the HTML output is also like: The image can't be oppened because it contains errors..</p>