show_code.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. if ($_REQUEST['filename']) { $filename = $_REQUEST['filename']; }
  3. else { die("No file specified"); }
  4. include("../mpdf.php");
  5. $mpdf=new mPDF('utf-8-s');
  6. $mpdf->debug=true;
  7. $mpdf->tabSpaces = 6;
  8. $mpdf->allow_charset_conversion=true;
  9. $mpdf->charset_in='windows-1252';
  10. //==============================================================
  11. preg_match('/example[0]{0,1}(\d+)_(.*?)\.php/',$filename,$m);
  12. $num = intval($m[1]);
  13. $title = ucfirst(preg_replace('/_/',' ',$m[2]));
  14. if (!$num || !$title) { die("Invalid file"); }
  15. if (preg_match('/\//', $filename) || !preg_match('/\.php$/',$filename)) { die("Hacking attempt"); }
  16. $html = '
  17. <h1>mPDF</h1>
  18. <h2>Example '.$num.'. '.$title.'</h2>
  19. <div style="border:1px solid #555555; background-color: #DDDDDD; padding: 1em; font-size:8pt; font-family: lucidaconsole, mono;">
  20. ';
  21. $lines = file($filename);
  22. $html .= '<pre>';
  23. foreach($lines AS $line) {
  24. $html .= htmlspecialchars($line);
  25. }
  26. $html .= '</pre>';
  27. $html .= '</div>';
  28. $mpdf->WriteHTML($html,2); // The 2 is important to prevent <style etc. being parsed
  29. $mpdf->Output();
  30. exit;
  31. //==============================================================
  32. //==============================================================
  33. //==============================================================
  34. //==============================================================
  35. //==============================================================
  36. ?>