<?PHP

$temp_dir 
'/home/virtual/site244/fst/var/www/html/wordpress/wp-content/uploads/2009/02/pdf_temp';
$temp_url '/wordpress/wp-content/uploads/2009/02/pdf_temp';

if(
$_FILES['uploadedfile']['type'] != 'application/pdf') {
  print 
"Don't be hatin'.";
  exit;
}

// clear out the temp_dir
if($handle opendir($temp_dir)) {
  while(
false !== ($file readdir($handle))) {
    if(
$file != "." && $file != "..") {
      
unlink("$temp_dir/$file");
    }
  }
  
closedir($handle);
}


$filename =  basename($_FILES['uploadedfile']['name']);

$target_path $temp_dir '/' $filename;

if(!
move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
  print 
"Something went horribly wrong.";
  exit;
}

$tfile =  str_replace('.''_'$target_path);
$jpg_file $tfile '.jpg';

system("convert -quality 100 -density 200x200 $target_path $jpg_file");

if(
file_exists($jpg_file)) {
  
$jpg_url $temp_url '/' basename($jpg_file);
}
else {
  
$date date('Gis');
  
system("zip -j -q -r $temp_dir/$date.zip $tfile*");
  
$jpg_url $temp_url '/' "$date.zip";
}
header("Location: $jpg_url");
?>