View Full Version : php question
svero
10-13-2004, 09:27 AM
Assuming my server is configured to treat http exe requests as php scripts how can I choose a different file to serve based on the results of some test? For example.. suppose someone downloads
http://www.twilightgames.com/download/x.exe
I'd like to have some php code run at that point which basically does
if(condition_met)
give downloader file x.exe
else
give downloader file x2.exe
- Steve
Tom Cain
10-13-2004, 10:30 AM
I believe you'll have to put the "x.exe" and "x2.exe" files in a different directory than the script, because the script and first file are both named "x.exe".
This may work, or at least may be a place to start. It's put together from a download script I use on several sites:
if(true)
$filename = "x.exe";
else
$filename = "x2.exe";
Header("Content-Type: application/octet-stream");
Header("Content-Disposition: attachment; filename=".$filename);
Header("Content-Length: ".filesize("myfiledir/".$filename));
readfile("myfiledir/".$filename);
ggambett
10-13-2004, 10:36 AM
Or even better
if (condition)
header("Location: http://...whatever.../file1.exe");
else
header("Location: http://...whatever.../file2.exe");
@Tom : I avoid manually using download headers whenever I can, I've read many posts in this forums reporting misc problems with that. Did you have any problem using these?
http://www.indiegamer.com/archives/t-1953.html
I wouldn't treat "*.exe" as php files... that's just odd. Use rewrite rules instead.
from .htaccess:
RewriteEngine On
RewriteBase /jnlp
RewriteRule downloads/(.*) jarbounce.php?file=$1 [NE]
It's this for the user:
http://onyx.bubblegumcrises.jp/jnlp/downloads/fake.jar
And this internally:
http://onyx.bubblegumcrises.jp/jnlp/jarbounce.php?file=fake.jar
This way you can run scripts and whatsoever... and even the crappiest browsers out there won't have a chance to screw anything up (because there is no difference on their side ;)).
Tom Cain
10-13-2004, 10:50 AM
Gabriel:
I've never had trouble with these download headers, even when building sites with old browser requirements. I've heard of problems also, but I've never seen them or had anyone report them not working on sites I've built. I thought the server in this scenario would treat the exe files as php scripts if the download headers weren't used, but I have never worked with a server configured to treat exe files as php scripts, so maybe it will download fine without the download headers.
oNyx's solution, though, looks like a simpler way to achieve the desired result.
Oh I forgot to mention xampp.
http://www.apachefriends.org/en/xampp.html
It's a complete (free) package. Apache, php, mysql and perl. After running the installer you have a nicely configurated running webserver, which you can use for "toying" around (did that the whole day long... duh) ;)
Without a local server testing such stuff would be quite painfull. [On a second thought... most likely you already have one, but I still think it's good to post that for the guys who don't have one]
Nikster
10-13-2004, 01:58 PM
Arse :) I spent a while the other week setting up Apache and friends to test my php scripts.. thanks for the link...
Diragor
10-13-2004, 02:16 PM
Awesome! I formatted and reloaded my system over the weekend, and just last night I downloaded the latest Apache, MySQL and PHP to get a test server running. Luckily I haven't installed and configured anything yet so I can use XAMPP instead. :) Thanks for the link!
Nutter
10-13-2004, 11:06 PM
svero, you may want to use this in combination with oNyx's post about RewriteRule (don't treat exes as php files!), as this will (hopefully) work with apps like GetRight to allow them to break files up into parts for simultaneous downloading: http://forums.indiegamer.com/showpost.php?p=8056&postcount=20
Powered by vBulletin™ Version 4.1.3 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.