-
help with dynamic pages
i really don't know php that well but i think it is what i need to use to do what i want. i have a page that has a bunch of links to programs to download. before the programs can be downloaded i would like to have them all goto the same page for a little information but the link on that page would depend on what link they clicked on the other page so they can download the correct program. that might sound a little confusing. so instead of having 10 or so copies of the same page i want each link to make its own copy and insert the path of the program to download. i hope you understand what i mean.
-
Well, it would depend on how you're going to store all of the information.. but you could make a 'download.php' and use GET to determine what file you were downloading. You might even want to use download IDs so that a filename wouldn't screw up the script. Anyway, the link to the file would be something like:
download.php?id=29844
OR
download.php?file=download.zip
You could use a variety of methods to store each downloads information (like a description, number of downloads, ratings, etc.), including MySQL or another database type or just a flat text file. Depending on how you were going to retrieve the information the script could change hugely.. but I'll make an example below for a script taking it from a MySQL database, using download IDs..
This is a bit of a long script, and is probably very poorly written, but it works. To myself, I'm not a very good programmer, but what I make works, so.. hmm, here goes.
PHP Code:
<title>downloads</title>
<style>
body { font: 10px verdana; color: #000000; }
td { font: 10px verdana; height: 14; }
a { font: 10px verdana; color: #000000; }
a:hover { text-decoration: none; }
.top { border: 1px solid #000000; border-top-style: none; border-left-style: none; border-right-style: none; }
.bot { border: 1px solid #000000; border-bottom-style: none; border-left-style: none; border-right-style: none; }
</style>
<?
/*********************************
* download.php *
*********************************
* author: david miles *
* email : [email][email protected][/email] *
* aim : l33tkows *
*********************************/
//mysql information
$mysql['host'] = "localhost"; //mysql server
$mysql['user'] = ""; //mysql username
$mysql['pass'] = ""; //mysql password
$mysql['db'] = "database"; //mysql database
$mysql['tbl'] = "download"; //mysql table
@mysql_connect($mysql['host'], $mysql['user'], $mysql['pass']) or die("Couldn't connect to $mysql[host]");
@mysql_select_db($mysql['db']) or die("Couldn't select database '$mysql[db]'");
//check if download info is requested
if(isset($_GET['id']) && $_GET['id'] > 0){
//it is, so select from database and spit it out
$info = "SELECT * FROM $mysql[tbl] WHERE id='$_GET[id]'";
$info = mysql_query($info);
$info = mysql_fetch_array($info);
//check to see if this file exists in database
if($info['id'] != ""){
//it exists, so print out info
?>
<h1>download #<? echo $info['id']; ?></h1>
<blockquote>
<b>name:</b> <? echo $info['name']; ?><br>
<b>file type:</b> <? echo $info['type']; ?><br>
<b>file size:</b> <? echo filesize("files/" . str_replace("/", ".", $info['date']) . "/" . $info['filename']); ?> bytes<br>
<b>date added:</b> <? echo $info['date']; ?><br>
<b>filename:</b> <? echo $info['filename']; ?><br>
<b>downloads:</b> <? echo $info['hits']; ?><br>
<b>rating:</b> <? echo $info['rate']; ?> | rate this file: <a href="rate.php?id=<? echo $_GET['id']; ?>&rate=+">+</a> / <a href="rate.php?id=<? echo $_GET['id']; ?>&rate=-">-</a><br>
<br>
<p>
<b>description:</b><br>
<? echo $info['desc']; ?>
</p>
<br>
<blockquote>
<b><a href="files/<? echo str_replace("/", ".", $info['date']) . "/" . $info['filename']; ?>">download now!</a></b>
</blockquote>
</blockquote>
<br><br>
<a href="download.php">back to download index</a><br><br>
<?
}else{
//it doesn't exist, print out error
echo "Incorrect file ID.";
}
}else{
//no file id was entered, display database index
//count the number of
$c = "SELECT COUNT(*) FROM $mysql[tbl]";
$c = mysql_query($c);
$c = mysql_fetch_array($c);
//get index info
$q_info = "SELECT id, name, type, date FROM $mysql[tbl]";
$q_info = mysql_query($q_info);
echo "<center>\n";
echo "<table width=475 cellspacing=0 cellpadding=0>\n";
echo " <tr>\n";
echo " <td class=top width=25 align=center>id</td>\n";
echo " <td class=top width=250>name</td>\n";
echo " <td class=top width=100>type</td>\n";
echo " <td class=top width=100>date</td>\n";
echo " </tr>\n";
while($info = mysql_fetch_array($q_info)){
//display the index info
$bgcolor = "ffffff";
if($info['id'] % 2){
$bgcolor = "c1c1c1";
}
$bgcolor = "#" . $bgcolor;
echo " <tr bgcolor=$bgcolor>\n";
echo " <td align=center>$info[id]</td>\n";
echo " <td><a href=\"?id=$info[id]\">$info[name]</a></td>\n";
echo " <td>$info[type]</td>\n";
echo " <td>$info[date]</td>\n";
echo " </tr>\n";
}
echo " <tr>\n";
echo " <td class=bot colspan=4 align=right>$c[0] files found</td>\n";
echo " </tr>\n";
echo "</table>\n";
echo "</center>\n";
}
?>
Here is a working example of the script I just put together:
http://blast.complex-sys.com/php/download/download.php
The files are all empty and there's only a few there; but you get the idea. This can be expanded on a lot after the simple stuff is worked out.
I'm hoping this is what you wanted, and if not, well, explain more.
-
thats exactly what i wanted...thanks a lot
-
If you need any help setting up the MySQL database or anything else, feel free to e-mail me at [email protected] or IM me on AIM. My AIM name is l33tkows.