Page 1 of 1

storing and recalling file links from mysql database

Posted: Mon Feb 09, 2004 11:28 am
by Infinity
please tell me how or if I can do this.
i have a database with a table called numberones which has at the moment 5 fields the 5th field is named dllink I want to store a link to the file in this field so that when i query mysql it displays DOWNLOAD in the 5th column and when you click on DOWNLOAD it will download the appropriate file. below is my code for displaying the results

Code: Select all

<?php
define('IN_PHPBB', true); 
$phpbb_root_path = './'; // relative directory path to your phpBB page 
include($phpbb_root_path . 'extension.inc'); 
include($phpbb_root_path . 'common.'.$phpEx); 

// 
// Start session management 
// 
$userdata = session_pagestart($user_ip, PAGE_INDEX); 
init_userprefs($userdata); 
// 
// End session management 
// 
$page_title = "inf_1_singles.php"; 

if ($userdata['session_logged_in'])    
{ 
echo "Welcome ";
echo $userdata[username];
echo " you r logged in.";

include("inf_music_header.tpl"); 
$navbar = (int)$_GET['navbar']; 
if(!isset($_GET['navbar'])) 
{ 
//$navbar = 5; 
} 
if ($navbar == 5) 
{  
include("inf_music_navbar_1950s.tpl"); 
} 
elseif ($navbar == 6) 
{  
include("inf_music_navbar_1960s.tpl"); 
} 
elseif ($navbar == 7) 
{  
include("inf_music_navbar_1970s.tpl"); 
}  


 

   $location = "localhost"; 
   $username = "xxxx"; 
   $password = "xxxx"; 
   $database = "MYMUSIC"; 
   $conn = mysql_connect("$location","$username","$password"); 
$year = (int)$_GET['year']; 
if(!isset($_GET['year'])) 

  
   if (!$conn) die ("Could not connect MySQL"); 
   mysql_select_db($database,$conn) or die ("Could not open database"); 

$query = "SELECT * FROM numberones  WHERE `year` = '$year'"; 
   $result = mysql_query($query); 
   $numrows = mysql_num_rows($result); 




echo "<table width='100%'  border='1' cellpadding='2' cellspacing='2' bordercolor='#006699' align='center'>"; 
echo "<tr>"; 
echo "<td width='100%' background='./templates/fisubsilversh/images/cellpic3.gif'><div align='center' class='style2 style3'><strong> 
          Number 1 Singles from $year </strong></div></td>"; 
echo "</tr>"; 
echo "</table>"; 
echo "<table width='100%'  border='1' cellpadding='2' cellspacing='2' bordercolor='#006699' align='center'>"; 




echo "<td width='13%' background='./templates/fisubsilversh/images/cellpic1.gif'><div align='center' class='style1'>Date</div></td>"; 
echo "<td width='33%' background='./templates/fisubsilversh/images/cellpic1.gif'><div align='center' class='style1'>Artist</div></td>"; 
echo "<td width='39%' background='./templates/fisubsilversh/images/cellpic1.gif'><div align='center' class='style1'>Title</div></td>"; 
echo "<td width='6%' background='./templates/fisubsilversh/images/cellpic1.gif'><div align='center' class='style1'>Wks</div></td>"; 
echo "<td width='9%' background='./templates/fisubsilversh/images/cellpic1.gif'><div align='center' class='style1'>d/l</div></td>";    

    
   while($row = mysql_fetch_array($result)) 



{ 
      echo "<tr><td background='./templates/fisubsilversh/images/cellpic_nav.gif'><div align='center'>$row[year]</div></td></tc>"; 
      echo "<tc><td background='./templates/fisubsilversh/images/cellpic_nav.gif'><div align='center'>$row[artist]</div></td></tc>"; 
      echo "<tc><td background='./templates/fisubsilversh/images/cellpic_nav.gif'><div align='center'>$row[title]</div></td></tc>"; 
      echo "<tc><td background='./templates/fisubsilversh/images/cellpic_nav.gif'><div align='center'>$row[weeksatone]</div></td></tc>"; 
     
	  
	 echo "<tc><td background='./templates/fisubsilversh/images/cellpic_nav.gif'><div align='center'>$row[dllink]</div></td></tr>"; 
} 



echo "</table>"; 

 
include("inf_music_footer.tpl"); 
// Release the Result Set
mysql_free_result($result);
// Close the connection
mysql_close($conn);

} 
else              
{          
echo "You r not logged in"; 
} 
?>
thanx

solved I think

Posted: Mon Feb 09, 2004 11:53 am
by Infinity
ok i think ive sussed this one out and for anyone who is interested here's the code

Code: Select all

<?php
define('IN_PHPBB', true); 
$phpbb_root_path = './'; // relative directory path to your phpBB page 
include($phpbb_root_path . 'extension.inc'); 
include($phpbb_root_path . 'common.'.$phpEx); 

// 
// Start session management 
// 
$userdata = session_pagestart($user_ip, PAGE_INDEX); 
init_userprefs($userdata); 
// 
// End session management 
// 
$page_title = "inf_1_singles.php"; 

if ($userdata['session_logged_in'])    
{ 
echo "Welcome ";
echo $userdata[username];
echo " you r logged in.";

include("inf_music_header.tpl"); 
$navbar = (int)$_GET['navbar']; 
if(!isset($_GET['navbar'])) 
{ 
//$navbar = 5; 
} 
if ($navbar == 5) 
{  
include("inf_music_navbar_1950s.tpl"); 
} 
elseif ($navbar == 6) 
{  
include("inf_music_navbar_1960s.tpl"); 
} 
elseif ($navbar == 7) 
{  
include("inf_music_navbar_1970s.tpl"); 
}  


 

   $location = "localhost"; 
   $username = "xxxx"; 
   $password = "xxxx"; 
   $database = "MYMUSIC"; 
   $conn = mysql_connect("$location","$username","$password"); 
$year = (int)$_GET['year']; 
if(!isset($_GET['year'])) 

//$username = (int)$_GET['username'];
//if(!isset($_GET['username']))
  
   if (!$conn) die ("Could not connect MySQL"); 
   mysql_select_db($database,$conn) or die ("Could not open database"); 

$query = "SELECT * FROM numberones  WHERE `year` = '$year'"; 
   $result = mysql_query($query); 
   $numrows = mysql_num_rows($result); 




echo "<table width='100%'  border='1' cellpadding='2' cellspacing='2' bordercolor='#006699' align='center'>"; 
echo "<tr>"; 
echo "<td width='100%' background='./templates/fisubsilversh/images/cellpic3.gif'><div align='center' class='style2 style3'><strong> 
          Number 1 Singles from $year </strong></div></td>"; 
echo "</tr>"; 
echo "</table>"; 
echo "<table width='100%'  border='1' cellpadding='2' cellspacing='2' bordercolor='#006699' align='center'>"; 




echo "<td width='13%' background='./templates/fisubsilversh/images/cellpic1.gif'><div align='center' class='style1'>Date</div></td>"; 
echo "<td width='33%' background='./templates/fisubsilversh/images/cellpic1.gif'><div align='center' class='style1'>Artist</div></td>"; 
echo "<td width='39%' background='./templates/fisubsilversh/images/cellpic1.gif'><div align='center' class='style1'>Title</div></td>"; 
echo "<td width='6%' background='./templates/fisubsilversh/images/cellpic1.gif'><div align='center' class='style1'>Wks</div></td>"; 
echo "<td width='9%' background='./templates/fisubsilversh/images/cellpic1.gif'><div align='center' class='style1'>d/l</div></td>";    

    
   while($row = mysql_fetch_array($result)) 



{ 
      echo "<tr><td background='./templates/fisubsilversh/images/cellpic_nav.gif'><div align='center'>$row[year]</div></td></tc>"; 
      echo "<tc><td background='./templates/fisubsilversh/images/cellpic_nav.gif'><div align='center'>$row[artist]</div></td></tc>"; 
      echo "<tc><td background='./templates/fisubsilversh/images/cellpic_nav.gif'><div align='center'>$row[title]</div></td></tc>"; 
      echo "<tc><td background='./templates/fisubsilversh/images/cellpic_nav.gif'><div align='center'>$row[weeksatone]</div></td></tc>"; 
	  echo "<tc><td background='./templates/fisubsilversh/images/cellpic_nav.gif'><div align='center'><a href="$row[dllink]">download</a></div></td></tr>"; 
} 



echo "</table>"; 

 
include("inf_music_footer.tpl"); 
// Release the Result Set
mysql_free_result($result);
// Close the connection
mysql_close($conn);

} 
else              
{          
echo "You r not logged in"; 
} 
?>

Posted: Mon Feb 09, 2004 12:06 pm
by Infinity
ok now i need to link to a file on another drive and this one i'm having no luck with
if you look at the code in the posts above dllink is where the paths to the files are stored and if i place the mp3 file in the phpbb2 root it downloads fine i.e dllink = filename.mp3 but if i make dllink = e:\singles\j\jimi\filename.mp3 when i click the link it does nothing ive seen it written somewhere the files must be in the phpbb2 root but there must be some way to link on another drive. any ideas