Hi guys

I have a download script. I'm storing files above webroot and using download script for making files available for download to users.

Now the problem is that when file download open/save dialogue box comes... if the user clicks on save they can save the file and then they can open it without any problem . But if they click on open then they can't open the file. It says file path not found or there was some error file could not be open.

Can someone please help me with this problem?

here is the code

<?php
//=======================
//=User defined settings=
//=======================


//Path to where the requested files should be(needs trailing slash);
$path="C:/program files/xampp/security/private/";

//=======================
//=The script, dont edit=
//=======================

//Just in case, function
if (!function_exists('mime_content_type')) {
   function mime_content_type($f) {
       $f = escapeshellarg($f);
       return trim( `file -bi $f` );
   }
}

//Get the requested file
$file = $_GET['file'];

//Stop the script if file selected is invalid
if( (  !$file ) or  ( !file_exists( $path . $file ) ) ) {
  die( "File wasnt set or it didnt exist" );
}

//What type of file is this.
$filetype=mime_content_type($path.$file);

//Set the filename
header("Content-Disposition: attachment; filename=\"$file\"");

//Set the content type
header('Content-type: '.$filetype);

//Read the file into the browser.
readfile( $path . $file );

?>

Thanks in Advance

    i just had to add
    header('Cache-control: private, must-revalidate');
    and open button works fine now

      Write a Reply...