topical media & game development

talk show tell print

professional-sql-06-public-files-download.php / php



  <?php
  include '../lib/common.php';
  include '../lib/config.php';
  
  // prevent users from traversing outside the base directory
  dir = BASEDIR . _POST['dir'];
  target = realpath(dir . '/' . _GET['file']);
  if (strpos(target, BASEDIR) !== 0)
  {
      die();
  }
  
  // send the file if it exists
  if (file_exists(target) && is_file(target))
  {
      header('Content-Type: application/force-download');
      header('Content-Disposition: attachment; filename="' .
          _GET['file'] . '";');
      header('Content-Transfer-Encoding: binary');
      header('Content-Length: ' . filesize(target));
      readfile(target);
  }
  ?>
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.