yobo Posted March 12, 2008 Share Posted March 12, 2008 hey All I am trying to create a download page I have managed to the upload page to add the file to the database etc.. however on my view.php, this page shows all the files that are in the database and allows the user to download a particular file to do this the view.php calls the download.php which processes the download. however I am unable to pass the id along to the download.php, can anyone help? this is the error on the view.php page <a href="download.php?id=<?php '.$id.' ?>"><?php="$name";?></a> <br> here is the source code for the view page <html> <head> <title>Download File From MySQL</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php //connect to database $dbcon = @mysql_connect('localhost', 'root'); if(!dbcon) { exit('<p> Unable to connect to database server</p>'); } if(!@mysql_select_db('uploads')) { exit('<p> Unable to select the database</p>'); } $query = "SELECT id, name FROM upload"; $result = mysql_query($query) or die('Error, query failed'); if(mysql_num_rows($result) == 0) { echo "Database is empty <br>"; } else { while(list($id, $name) = mysql_fetch_array($result)) { ?> <a href="download.php?id=<?php '.$id.' ?>"><?php="$name";?></a> <br> <?php } } ?> </body> </html> and this is the download.php page <?php if(isset($_GET['id'])) { // if id is set then get the file with the id from database //connect to database $dbcon = @mysql_connect('localhost', 'root'); if(!dbcon) { exit('<p> Unable to connect to database server</p>'); } if(!@mysql_select_db('uploads')) { exit('<p> Unable to select the database</p>'); } $id = $_GET['id']; $query = "SELECT name, type, size, content " . "FROM upload WHERE id = '$id'"; $result = mysql_query($query) or die('Error, query failed'); list($name, $type, $size, $content) = mysql_fetch_array($result); header("Content-length: $size"); header("Content-type: $type"); header("Content-Disposition: attachment; filename=$name"); echo $content; exit; } ?> thanks all sorry for the lenghtly post Joe Quote Link to comment Share on other sites More sharing options...
yobo Posted March 12, 2008 Author Share Posted March 12, 2008 Not to worry guys i have sorted it Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.