FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

php download system prob

 


riyadh
i wrote a download system in php so tht i can liink my downloads like
Quote:
http://www.mysite.net/download.php?file=2
. when i type this in the browser's address bar, nothing is returned. the code for the download.php file is:
Code:

<?php
include('config_downloads.php');

if (isset($file)){

   dbConnect();
   $sql = "select address from downloads";
   $result = mysql_query($sql);
   $rows = mysql_num_rows($result);
   
   for ($x=0;$x<$rows;$x++) {
   $urlarray[$x] = mysql_result($result,$x);
   }
   
   $request = $urlarray[$file];
   
   if (!$request) {
      echo ("Error on url string");
   }
   else {
      header("Location: $request");
   }
   
   $query = "UPDATE downloads SET downloads=downloads+1 WHERE id = $file";
   $result = mysql_query($query);
   if (!$result){
      echo("Database Error");
   }
   $datetime = date('d M Y h:i:s a');
   $querystat = "INSERT INTO stats SET ID='$file', IP='$REMOTE_ADDR', Date/Time='$datetime'";
   $resultstat = mysql_query($querystat);
   if (!$result){
      echo("Database Error");   
   }
   
}

if (isset($downloads)){
   dbConnect();
   $query = "SELECT downloads FROM downloads WHERE id = $downloads";
   $result = mysql_query($query);
   $hits = mysql_result($result,0);
   echo($hits);
}
?>


where
Quote:
address
is the real address of the files,
Quote:
id
is the id of the files etc.[/quote]
shamil
You should use
Code:
isset($_GET['file'])
instead
Code:
isset($file)

Codes after the
Code:
   if (!$request) {
      echo ("Error on url string");
   }
   else {
      header("Location: $request");
   }

dont get executed unless there is error. I think you didin't wish to do that. If so precede them before the line
Code:
header("Location: $request");
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.