Re: choosing the name to save a file as in a script

From: Date: Wed, 27 Dec 2000 01:21:07 +0000
Subject: Re: choosing the name to save a file as in a script
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-31898@lists.php.net to get a copy of this message
I completely understood what Blaster was asking for, and I believe I supplied it here - although not with the EXACT syntax asked for. The syntax, as Blaster pointed out, seemed to be the tipoff to certain browsers as to what filetype to save something as. We got around this problem by using the header() command to send header info down to the browser which, in our cases, generally gets the browsers to do what we want (save as a certain file type). Ken wrote: > To attempt clarify what Blaster, the original poster of the question, seems to be actually > asking about: > > The way the site he saw did it involved a URL like script.php/myfile.zip?parameter=value... > > script.php actually goes ahead and delivers myfile.zip to the user's browser. > > The positive functionality that that particular URL structuring provides is that the > user's BROWSER, when prompting the user to save the file, puts "myfile.zip" as the > default filename to save as. > > Using any of the other approaches (i.e.: script.php?filename=myfile.zip, or > script.php?fileid=###), the browser fills in "script.php" as the default filename, which > is not what we want. > I beg to differ - the code I supplied below is the foundation of a file distribution module we have in place and it works - at least, it works from Apache as a web server running on Linux, with both Netscape and IE users using it from Windows as browser clients. I understand the question revolves some around getting this to work under IIS with PHP. Has any tried a variation of the code I sent below under IIS/PHP? It *should* work. Generally it's IE that will start to save the file being sent as whatever the script file extension's type is. (files from script.php are all downloaded as xxx.php, regardless of file type). I believe the Content-Disposition headers we send are what avoid that issue in our case. > > Of course, the php script could redirect to the actual .zip file, but it seems that the heart > of why Blaster wants to have the script do the delivery itself is to keep all the control of file > delivery within the script. > > (Now, why he wants that, I don't know. There might be a better solution than this one for > what his goal is, but I don't know what the real goal is in this case.) > > Blaster, feel free to correct me if I've gotten this wrong. > > And, as far as getting script.php/myfile.zip working, it's easy if you're using > Apache, and PHP is running as an Apache module. Beyond that, I don't know. > > - Ken > kenzo@free-music.com > > At 07:22 PM 12/26/00 -0500, Michael Kimsal wrote: > >Don't bother with the 'filename.ext' part - just get the ID parameter. > >Look up the filename in a database of what the filename.ext should > >be for file ID xxxxxx. > > > >Then send > > > > header("Content-type: ".$db->Record["filemime"]." ; > >filename=".$db->Record["filename"]); > > header("Content-Disposition: attachment; > >filename=".$db->Record["fullfilename"] ); > > $f = fopen($db->Record["localfilename"],"r"); > > $x = fread($f,filesize($db->Record["localfilename"])); > > fclose($f); > > echo $x; > > exit(); > > > >well - don't use $db->Record, etc. This is code we use to send > >a file down to someone who sends in a particular string ID. We control > >the filename, the MIME type, and who gets access to what file. Haven't > >tried it under IIS using PHP, but I'd think the underpinnings are > >pretty much the same across the board. > > > > > >Blaster wrote: > > > > > Hi everyone, > > > > > > I've seen something very interesting on some site that would allow me to use > > > PHP-authentification to allow download of certain files.... Here's what the > > > link on the site looks like: > > > > > > > > >http://www.whatever.com/view.php3/filename.ext?id=17982 > > > > > > Now, the script that sends the file is view.php3. What this does is get a > > > file with id 17982, either by reading it from a database or something (not > > > important) and sends it back to the browser and the browser thinks it is > > > actually file "filename.ext"... > > > > > > What I don't get is how can you pass "/filename.ext?id=17982" as an > > > argument? I tried it and the web server will of course look for file > > > "filename.ext", but it doesn't exist since view.php3 is obviously not > > > a > > > directory... > > > > > > Any ideas how this can be achieved? I thought it could be some kind of 404 > > > error redirection to a php script, but then all bad links on the whole site > > > would be sent to that script and they don't appear to be (at least I get a > > > normal 404 error everywhere else) > > > > > > Thanks for your time

« previous php.general (#31898) next »