Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.