PHP download script shows blank window

Posted on 2010-08-31
Last Modified: 2013-12-25
The following script shows blank window when file download begins. I want the current page remains, just like clicking on a static download link.

      $file = $_GET['ver'];
      echo "<meta http-equiv=refresh content='0; url=$file'>";
Question by:joggx
1 Comment

Accepted Solution

plymelk earned 500 total points
ID: 33573338
The meta tag above replaces the current page with the download file.
The file download should be inline with the existing page or a thank you page, etc.
The attached download script came from



// place this code inside a php file and call it f.e. "download.php"

$path = $_SERVER['DOCUMENT_ROOT']."/path2file/"; // change the path to fit your websites document structure

$fullPath = $path.$_GET['download_file'];


if ($fd = fopen ($fullPath, "r")) {

    $fsize = filesize($fullPath);

    $path_parts = pathinfo($fullPath);

    $ext = strtolower($path_parts["extension"]);

    switch ($ext) {

        case "pdf":

        header("Content-type: application/pdf"); // add here more headers for diff. extensions

        header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // use 'attachment' to force a download



        header("Content-type: application/octet-stream");

        header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");


    header("Content-length: $fsize");

    header("Cache-control: private"); //use this to open files directly

    while(!feof($fd)) {

        $buffer = fread($fd, 2048);

        echo $buffer;



fclose ($fd);


// example: place this kind of link into the document where the file download is offered:

// <a href="download.php?download_file=some_file.pdf">Download here</a>


Open in new window


Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
TCPDF HTML Table of Contents how can I create leading dots 7 39
php email 2 26
Php pie charts 3 26
Amazon Redshift 2 25
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
The viewer will learn how to count occurrences of each item in an array.

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now