file downloads (again)

From: Date: Mon, 17 Jun 2002 05:57:35 +0000
Subject: file downloads (again)
Groups: php.general 
Request: Send a blank email to php-general+get-102469@lists.php.net to get a copy of this message
Hi all, I've been messing with, researching and using chunks of code from the archives of this list, the manual, the user-contributed notes, etc etc for about a week, TRYING to get file downloads to work. Background: trying to make MP3 downloads available to only members (session based login). I've even been digging around inside apps like phpMyAdmin to see how their work. Anyhoo, the end result is that I can't get them working... in Netscape 6 (Mac), the file downloads okay, but somewhere along the way, the file was corrupted, and my MP3 players refuse to play the file. In IE 5.5 (Mac), the file doesn't download... instead, IE takes over, and tries to play it using IE's quick time plugin, via the browser window, but fails (again, due to corruption or file type I guess). Here's *A version* of what I've been trying *without sessions*: <? $file = $_GET['file']; if($file == "") { $nofile = 1; } else { $file_location = "mp3/".$file; if(!file_exists($file_location)) { $nofile = 1; } else { if(strstr($_SERVER["HTTP_USER_AGENT"], "MSIE") OR strstr($_SERVER["HTTP_USER_AGENT"], "Opera")) { header("Content-type: application/octetstream"); header("Content-Disposition: inline; filename={$file_location}"); } else { header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename={$file_location}"); } } } ?> <HTML> <BODY>your file should automatically start downloading</BODY> </HTML> I think my main problems revolve around: a) reading code / opinions / methods from a wide variety of sources b) not fully understanding headers, and the problems with IE and the content-disposition. Any code fragments, links or advice would be greatly appreciated. Justin French

« previous php.general (#102469) next »