RE: [PHP] file downloads (again)

From: Date: Mon, 17 Jun 2002 08:52:40 +0000
Subject: RE: [PHP] file downloads (again)
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-102481@lists.php.net to get a copy of this message
You're sending a application/octet-stream header and an HTML header at the same time... I don't see where your sending any file data, but that's just a snippet of code, though. In order to send the file to the browser, you have to set the application/octet-stream header, then do something like passthru($filename). That's it. You can't do that and HTML at the same time, though. Also note that if you're storing your mp3 inside of your web directory, anyone can just type in the URL to it and download whatever they want. You should be storing them outside of the web root. ---John Holmes... > -----Original Message----- > From: Justin French [mailto:justin@indent.com.au] > Sent: Monday, June 17, 2002 1:58 AM > To: php > Subject: [PHP] file downloads (again) > > 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 > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#102481) next »