Displaying Code on the Web

Categories: blog



There's multiple ways to display code, using whatever highlighter you
want (GeSHi, Google Syntax Highlighter), .phps extension (if your
hosting supports it), and many more.

Since the HTML text editor automagically encode characters, so I added an option to download the file.
I've added a download script which will allow users to download files.

PHP:
  1. $mm_type="application/octet-stream";
  2.  
  3. $file = '';
  4. $filename = '';
  5.  
  6. $filename = $_GET['download'];
  7. switch($filename){
  8.     case "truncate":
  9.         $file = "truncate.php";
  10.         break;
  11.     case "download":
  12.         $file = "download_sample.php";
  13.         break;
  14. }
  15.  
  16. header("Cache-Control: public, must-revalidate");
  17. header("Content-Type: " . $mm_type);
  18. header("Content-Length: " .(string)(filesize($file)) );
  19. header('Content-Disposition: attachment; filename="'.$file.'"');
  20. header("Content-Transfer-Encoding: binary\n");
  21.  
  22.  
  23.  
  24.                  
  25. readfile($file);

No Comments yet »

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Powered by WordPress with GimpStyle Theme design by Horacio Bella.
Entries and comments feeds. Valid XHTML and CSS.