Hi All,
I've been struggling with a number of different snippets of code to get the following script to force download. Everything I try won't connect. Unfortunately, because I'm such a novice, I can't find where the problem lies. Could anyone help me 'plug in" the right code to make this work correctly?

As always, Thanks!

$sql = "select * from mp3_library, customer_orders where (email='$email' and (customer_orders.item1=mp3_library.code or customer_orders.item2=mp3_library.code or customer_orders.item3=mp3_library.code or customer_orders.item4=mp3_library.code or customer_orders.item5=mp3_library.code))";

$result= mysql_query($sql) or die(mysql_error());

echo "<table border='0'>
<tr>
</tr>";

while($row = mysql_fetch_assoc($result)) 

{ 
echo "<tr>"; 
echo "<td>" . $row['artist'] . "</td>";
echo "<td>&nbsp;<td>";
echo "<td>" . $row['track'] . "</td>";
echo "<td>&nbsp;<td>";
echo "<td><form><input type='button' name='download' value='Download File' onclick='window.location = \"".$row['link']."\"' /></form></td>";
echo "</tr>"; 
} 

echo "</table>"; 
?>

Recommended Answers

All 2 Replies

Hi,

its not possible to just download an mp3 file straight off, you need a little intervention.

try this script

http://elouai.com/force-download.php

hope it helps.

paul

There are a lot of good examples of forcing a download at:
http://www.php.net/manual/en/function.header.php

The example posted at: http://elouai.com/force-download.php
does not validate the file to send as a download. Thus a malicious user can download any file on that server, that is readable by PHP.

You have to make sure the script only allows the download of files in directories you specify. Some examples in the PHP manual page:
http://www.php.net/manual/en/function.realpath.php

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.