Link to home
Start Free TrialLog in
Avatar of Jason92s
Jason92sFlag for Afghanistan

asked on

Accessing Zip Files Outside Public_HTML Folder

I have a need to allow users to download ZIP files that reside outside the Public_HTML folder and found a PHP script that does just that -

It works great for PDF files but when I put a zip file in, the browser tries to save/open secure.php for some reason.  I shrunk the code down a bit as follow:

Link Page to download
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<body >
<a href="secure.php?">File Linke</a>

Open in new window

secure.php file:

  $folder = realpath('/home/rogersho/tester');
  $file = realpath($folder.'/'.$_GET['file']);
  header(sprintf("Content-type: %s;",getMimeType($file)));

   function getMimeType ( $filename ) {
    //MIME MAP
$mime_extension_map = array(
    'pdf'           => 'application/pdf',
    'zip'           => 'application/zip'
    //Get Extension

    $ext = strtolower(substr($filename,strrpos($filename,'.') + 1));
      return 'application/octet-stream';
      return $mime_extension_map[$ext];
    return 'x-extension/' . $ext;

Open in new window

Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jason92s


Oh, now I see what you're saying.  Perfect, works great, thank you.
Great!  Thanks for the points and good luck with the project, ~Ray