skot Posted September 3, 2008 Share Posted September 3, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/122470-downloadphp/ Share on other sites More sharing options...
DeanWhitehouse Posted September 3, 2008 Share Posted September 3, 2008 Could you not strip the spaces in the file name when requesting or are they needed? Quote Link to comment https://forums.phpfreaks.com/topic/122470-downloadphp/#findComment-632382 Share on other sites More sharing options...
skot Posted September 3, 2008 Author Share Posted September 3, 2008 They're needed as my main script simply shows a table row for every .mp3 or .wma found within the directory. Most of the files do contain spaces. The page can be viewed at www.bridgey.net/music Quote Link to comment https://forums.phpfreaks.com/topic/122470-downloadphp/#findComment-632608 Share on other sites More sharing options...
DeanWhitehouse Posted September 3, 2008 Share Posted September 3, 2008 Ok, when i click on a file (tracey in my room ...) it just loads quicktime and plays the song in the browser, so i cant see any problem , but try replacing any spaces with %20 Quote Link to comment https://forums.phpfreaks.com/topic/122470-downloadphp/#findComment-632719 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.