/    Sign up×
Community /Pin to ProfileBookmark

Download File

Hello! The following code, uploads an MP3 file to a folder located in the root directory of the server, whilst adding the files path to a database.

For each record in the database, how do I display the path as a link and upon a link being clicked, download the file?

[CODE]if (($_FILES[“file”][“type”] == “audio/mpeg”))
{
if ($_FILES[“file”][“error”] > 0)
{
echo “Return Code: ” . $_FILES[“file”][“error”] . “<br />”;
}
else
{
echo “Upload: ” . $_FILES[“file”][“name”] . “<br />”;
echo “Type: ” . $_FILES[“file”][“type”] . “<br />”;
echo “Size: ” . ($_FILES[“file”][“size”] / 1024) . ” Kb<br />”;
echo “Temp file: ” . $_FILES[“file”][“tmp_name”] . “<br />”;

if (file_exists(“upload/” . $_FILES[“file”][“name”]))
{
echo $_FILES[“file”][“name”] . ” already exists. “;
}
else
{
$file = (“upload/” . $_FILES[“file”][“name”]);
move_uploaded_file($_FILES[“file”][“tmp_name”],
“upload/” . $_FILES[“file”][“name”]);
echo “Stored in: ” . “upload/” . $_FILES[“file”][“name”];

mysql_query(“INSERT INTO Music (Path)
VALUES(‘$file’)”);
}
}
}
else
{
echo “Invalid file”;
}[/CODE]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@UI-ZEIKVKNov 15.2007 — Just show the link stored in the database. Browser can't operate mp3 files, So it will force to download file.
×

Success!

Help @Dysan spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...