Jump to content

Download.php


skot

Recommended Posts

Hi

 

Instead of regular download links I'd like to start using a force-download script to push files to the users browser. This works ok if the file name requested doesn't contain any spaces, but if it does the browser attempts to download a 0 bytes file called the first word of the original filename..

 

Is there any way around this? I'm trying to avoid manually renaming almost 600 files..

 

foreach ($dirArray as $file) {

    echo "<tr background=\"http://bridgey.net/img/row_bg.gif\">\n";
    echo "<td align=\"left\" background=\"http://bridgey.net/img/row_bg.gif\">";
    echo "<font face=\"verdana\" size=\"2\" color=\"#D9F4FD\"><b> ";
echo "<a href=\"download.php?fileName=". $file['name'] ."\"><img src=\"../img/star.gif\" border=\"0\">";
    echo $file['name'] . "</a></b></font></td>\n";
    echo "<td align=\"center\" background=\"http://bridgey.net/img/row_bg.gif\">{$file['ext']}</td>\n";
    echo "<td align=\"center\" background=\"http://bridgey.net/img/row_bg.gif\">{$file['size']} " . MB ."</td>\n";
    echo "<td align=\"center\" background=\"http://bridgey.net/img/row_bg.gif\">{$file['date']}</td>\n";
    echo "</tr>\n";
}

 

 

Contents of download.php:-

 

<?php

$fileName = $_REQUEST['fileName'];

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 

header("Content-Type: application/force-download");
header( "Content-Disposition: attachment; filename=".basename($fileName));

header( "Content-Description: File Transfer");
header('Accept-Ranges: bytes');
header('Content-Length: ' . filesize($fileName));
@readfile($fileName);

?>

 

Thanks for your time ;)

Link to comment
https://forums.phpfreaks.com/topic/122470-downloadphp/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.