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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to count occurrences of each item in an array.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

705 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

19 Experts available now in Live!

Get 1:1 Help Now