User Profile Music Upload Help
Posted: Sun Jun 22, 2008 1:56 pm
Hi,
I am converting a script that will let users register with my website and have a user profile page. I want them to be able to upload a media file and have it play back from their page with something like JW Player.
I've converted a piece of script and I've got the upload working, so when a user goes to their profile page they can upload a media file and it is stored in my database with their profile ID. But I am having real problems downloading/retrieving the path to the media file so that I can display it in a flash player.
I'm assuming it's because to download media you should use '$id = $_GET['id'];' but I need it to be the users ID.
Here are the scripts that I have been working on so far... Any help or a point in the right direction would be much appreciated...
I converted the below 'Bookmarks' script (which allows users to upload a simple hyperlink to their profile) into a media upload script:
Original Bookmark Script:
Above script converted to Media Upload:
The Display Bookmarks Script (which I would like to convert to media upload):
And the below script is what I've been trying to trying to mix in with the above script:
I'm still a bit of a noobie, that's why I've been taking bits of script from here and there...
Cheers!
I am converting a script that will let users register with my website and have a user profile page. I want them to be able to upload a media file and have it play back from their page with something like JW Player.
I've converted a piece of script and I've got the upload working, so when a user goes to their profile page they can upload a media file and it is stored in my database with their profile ID. But I am having real problems downloading/retrieving the path to the media file so that I can display it in a flash player.
I'm assuming it's because to download media you should use '$id = $_GET['id'];' but I need it to be the users ID.
Here are the scripts that I have been working on so far... Any help or a point in the right direction would be much appreciated...
I converted the below 'Bookmarks' script (which allows users to upload a simple hyperlink to their profile) into a media upload script:
Original Bookmark Script:
Code: Select all
<?php
if($_SERVER[PHP_SELF]=="/include/bm_add.inc.php")
{
header("Location: /index.php");
exit;
}
$connection = @mysql_connect("$db_host", "$db_user", "$db_pass") or die("Couldn't connect.");
$db = @mysql_select_db($db_name, $connection) or die("Couldn't select database.");
$sql = "SELECT profile_url FROM $tbl_profiles WHERE profile_id = \"$auth[member_id]\"";
$result = @mysql_query($sql,$connection) or die("Couldn't execute profile URL query.");
while ($row = mysql_fetch_array($result)) {
$my_url = $row['profile_url'];
$my_fullurl = "$userurl/$my_url";
}
if($_POST['action'] == "create") {
$bm_name = $_POST['bm_name'];
$bm_url = $_POST['bm_url'];
if(empty($bm_name)) {
echo "<p>You didn't enter a title!</p>
<p align=\"center\"><input id=\"button\" type=button value=\"BACK\" onClick=\"history.go(-1)\"></p>";
include("include/footer.inc.php");
exit;
}
if(empty($bm_url)) {
echo "<p>You didn't enter a URL!</p>
<p align=\"center\"><input id=\"button\" type=button value=\"Try again\" onClick=\"history.go(-1)\"></p>";
include("include/footer.inc.php");
exit;
}
$connection = @mysql_connect("$db_host", "$db_user", "$db_pass") or die("Couldn't connect.");
$db = @mysql_select_db($db_name, $connection) or die("Couldn't select database.");
$sql = "INSERT INTO $tbl_bookmarks (bm_owner, bm_name, bm_url)
VALUES (\"$auth[member_id]\", \"$bm_name\", \"$bm_url\")";
$result = @mysql_query($sql,$connection) or die("Couldn't execute new bookmark query.");
echo "<p>Your link has been added!</p>
<p align=\"center\"><a class=\"small\" href=\"$PHP_SELF\">ADD ANOTHER?</a></p>
<p align=\"center\"><a class=\"small\" href=\"$my_fullurl\">BACK TO PROFILE</a></p>";
include("include/footer.inc.php");
exit;
} else {
?>
<form action="<? $PHP_SELF ?>" method="POST">
<table border="0" align="center" cellpadding="3" cellspacing="0">
<tr>
<td valign="top">
<p>TITLE:</p>
</td>
<td valign="top">
<p><input class="form" type="text" name="bm_name" maxlength="30" size="30"></p>
</td>
</tr>
<tr>
<td valign="top">
<p>URL:</p>
</td>
<td valign="top">
<p><input class="form" type="text" name="bm_url" value="http://" maxlength="150" size="30"></p>
</td>
</tr>
<tr>
<td valign="top">
<p><input type="hidden" name="action" value="create"></p>
</td>
<td valign="top">
<p><input id="button" type="submit" value="SUBMIT">
<input id="button" type=button value="CANCEL" onClick="history.go(-1)"></p>
</td>
</tr>
</table>
</form>
<p> </p>
<? } ?>Code: Select all
<?php
if($_SERVER[PHP_SELF]=="/include/music_add.inc.php")
{
header("Location: /index.php");
exit;
}
$connection = @mysql_connect("$db_host", "$db_user", "$db_pass") or die("Couldn't connect.");
$db = @mysql_select_db($db_name, $connection) or die("Couldn't select database.");
$sql = "SELECT profile_url FROM $tbl_profiles WHERE profile_id = \"$auth[member_id]\"";
$result = @mysql_query($sql,$connection) or die("Couldn't execute profile URL query.");
while ($row = mysql_fetch_array($result)) {
$my_url = $row['profile_url'];
$my_fullurl = "$userurl/$my_url";
}
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$connection = @mysql_connect("$db_host", "$db_user", "$db_pass") or die("Couldn't connect.");
$db = @mysql_select_db($db_name, $connection) or die("Couldn't select database.");
$sql = "INSERT INTO upload (music_owner, name, size, type, content ) ".
"VALUES ('$auth[member_id]', '$fileName', '$fileSize', '$fileType', '$content')";
$result = @mysql_query($sql,$connection) or die("Couldn't execute new music query.");
echo "<br />File $fileName uploaded<br />
<p align=\"center\"><a class=\"small\" href=\"$PHP_SELF\">ADD ANOTHER?</a></p>
<p align=\"center\"><a class=\"small\" href=\"$my_fullurl\">BACK TO PROFILE</a></p>";
include("include/footer.inc.php");
exit;
} else {
?>
<form action="<? $PHP_SELF ?>" method="POST" enctype="multipart/form-data">
<table border="0" align="center" cellpadding="3" cellspacing="0">
<tr>
</tr>
<tr>
<td valign="top">
<p>IMAGE/MP3:</p>
</td>
<td valign="top">
<p><input class="form" type="file" name="userfile" id="userfile" size="30"></p>
</td>
</tr>
<tr>
<td valign="top">
<p>MUSIC:</p>
</td>
<td valign="top">
<p><input class="form" type="file" name="music_song1" size="30"></p>
</td>
</tr>
<tr>
<td valign="top">
<p><input type="hidden" name="action" value="create"></p>
</td>
<td valign="top">
<p><input id="upload" name="upload" type="submit" value="SUBMIT">
<input id="button" type=button value="CANCEL" onClick="history.go(-1)"></p>
</td>
</tr>
</table>
</form>
<p> </p>
<? } ?>Code: Select all
<?php
if($_SERVER[PHP_SELF]=="/include/profiles/bm_show.inc.php")
{
header("Location: /index.php");
exit;
}
$connection = @mysql_connect("$db_host", "$db_user", "$db_pass") or die("Couldn't connect.");
$db = @mysql_select_db($db_name, $connection) or die("Couldn't select database.");
$sql = "SELECT * FROM $tbl_bookmarks WHERE bm_owner = \"$profile_id\" ORDER BY bm_id DESC";
$result = @mysql_query($sql,$connection) or die("Couldn't execute bookmark query.");
$num=mysql_num_rows($result);
if($num < 1){
echo "<center>No Links yet.</center>";
}
?>
<ul>
<?
while ($row = mysql_fetch_array($result)) {
$bm_id = $row['bm_id'];
$bm_name = $row['bm_name'];
$bm_url = $row['bm_url'];
if($profile_id == $auth[member_id]) {
$usredit = "<a href=\"$siteurl/bm_edit.php?bm_id=$bm_id\">
<img src=\"$imgurl/edit.gif\" align=\"absmiddle\" alt=\"Edit\" title=\"Edit\" border=\"0\"></a> ";
}
echo "<li>$usredit<a href=\"$bm_url\" target=\"_blank\"> $bm_name</a></li>";
}
?>
</ul>Code: Select all
<?
if(isset($_GET['id']))
{
include 'library/config.php';
include 'library/opendb.php';
$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-Disposition: attachment; filename=$name");
header("Content-length: $size");
header("Content-type: $type");
echo $content;
include 'library/closedb.php';
exit;
}
?>
<html>
<head>
<title>Download File From MySQL</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?
include 'library/config.php';
include 'library/opendb.php';
$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=<?=$id;?>"><?=$name;?></a> <br>
<?
}
}
include 'library/closedb.php';
?>
</body>
</html>Cheers!