• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

How would I do this?

DarkTemplar194

New Member
Ok. I want to make a download.php file that like on many sites, when you put a ?id=(whatever) suffix after it it downloads a specific file. What I'd like to know is, how do you declare what the ID equals and how to set what file that ID loads?

For example:

download.php?id=14

The 14 part. How do I tell the php what the 14 (not just the ?id part) includes into the page???

Help appreciated! :)

dt
 
download.php :
PHP:
<?php
$f = array("", "file1", "file2", "file3") ;
if (isset($HTTP_GET_VARS['id'])) readfile($f[$HTTP_GET_VARS['id']]) ;
?>
download.php?id=3 will return file3 .
 
Yea, but instead of downloading the file it displays it as weird symbol text thingies on the page. For example a .ram file just displays the .rm destination instead of loading in realplayer! How do I make it actually load? :p
 
PHP:
<?php
header("Content-type: audio/x-pn-realaudio-plugin");
if (strstr($GLOBALS["HTTP_USER_AGENT"], "MSIE")) header("Content-Disposition: filename={$HTTP_GET_VARS['id']}.ram"); // For IE
else header("Content-Disposition: attachment; filename={$HTTP_GET_VARS['id']}.ram"); // For Other browsers
$f = array("", "file1.rm", "file2.rm", "file3.rm") ;
if (isset($HTTP_GET_VARS['id'])) readfile($f[$HTTP_GET_VARS['id']]) ;
?>

(Thanks to biggulp for "Content-Disposition" code)
 
Last edited:
<?php

header("Content-type: application/octet-stream");

if (strstr($GLOBAL["HTTP_USER_AGENT"], "MSIE")) header("Content-Disposition: filename={$HTTP_GET_VARS['id']}"); // For IE

else header("Content-Disposition: attachment; filename={$HTTP_GET_VARS['id']}"); // For Other browsers

print $image;

$f = array("", "file1", "file2", "file3") ;

if (isset($HTTP_GET_VARS['id'])) readfile($f[$HTTP_GET_VARS['id']]) ;

?>
 
Uh... wtf? That makes the download.php file, along with any ?id=1 or whatever after it try to download like some other file. It says "Downloading file download.php from (whatever) etc. etc." as like what you would do with a ZIP or EXE file??? :confused:
 
<?
$files = array("", "file1.ram", "file2.ram", "file3.ram"); //array value 1 has no value unless you want download.php?id=0

$image = fread(fopen($files[$HTTP_GET_VARS['id']], "r"), filesize($files[$HTTP_GET_VARS['id']])); //open and assign to $image

header("Content-type: application/octet-stream");

if (strstr($GLOBAL["HTTP_USER_AGENT"], "MSIE"))
header("Content-Disposition: filename={$HTTP_GET_VARS['id']}.ram"); // For IE
else
header("Content-Disposition: attachment; filename={$HTTP_GET_VARS['id']}.ram"); // For Other browsers

print $image;
?>
 
Last edited:
Just a note :
I made a mistake : change all "$GLOBAL"s -> to "$GLOBALS" .
And remove that "print $image;" line .I copy, pasted it and forgot to delete this line :)
(I corrected my post)
 
sorry, i didn't know it works. anyway it's better to use their respective arrays ($_SERVER & $HTTP_SERVER_VARS)
 
Back
Top