Jump to content

Uploading mp3s to database or server?


spires

Recommended Posts

Hi,

Can any one tell me if its posiable to  Upload mp3s to your database or server?
I've been looking on php.net but cant find anything on this.
I now know hoe to upload images to the server, is it done in the same way?

I'm try to build a shopping cart from a musician, and have the cart play a sample of the mp3,
so customers can hear the track before they buy.

Thanks
Link to comment
Share on other sites

example ok

[code]
---------form-----------------------------------------------------------

<html>
<head>
<body>
<h1>please upload music!</h1><br>


<form enctype="multipart/form-data" action="members_upload_music_result.php" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="320834100">
<br>
please choose a music file
<br>
<input type="file" name="userfile">
<br>
<input type="submit" value="send">
<br>


</form>
</html>
</body>



---------------upload result----------------

<? session_start();


$db=mysql_connect("localhost" ,"xxx","xxx");

mysql_select_db("promotor",$db);



$query="select * from members_music_uploads where name='$name' and id='$id'";

$result=mysql_query($query);

while($row=mysql_fetch_assoc($result)) {

if($row["userfile_name"]=1) {

echo "<b>Sorry you have a video already</b><br><br><a href='members_update_music_form.php'>Update music</a><br><br>";
exit;
}
}


$date_sent=date("d-m-y");

if(!$userfile=="none") {
echo"no file specified<br><br><br><br><a href='members_upload_music_form.php'>please try agin</a><br><br>";
exit;
}


$uploaddir ="members_music/";
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

$size=$_FILES['userfile']['size'];


$type=($_FILES['userfile']['type']=="audio/mpeg");

if($size <= 320834100) {

if($type) {

if(move_uploaded_file($_FILES['userfile']['tmp_name'],$uploadfile)) {


$userfile_name=addslashes($userfile_name);

$query="insert into members_music_uploads values('$id','$name','$date_sent','$userfile_name')";

$result=mysql_query($query);

echo "file uploaded";

}else{
echo"no file uploaded <br><br><br><a href='members_upload_music_form.php'>please try agin</a><br><br>";
exit;
}


}else{
echo"sorry wrong file type .mp3 only<br><br><br><a href='members_upload_music_form.php'>please try agin</a><br><br>";
exit;
}

}
?>





---------------------get the music out--------------------------

<?

$music_query="SELECT * from members_music_uploads where id='$id'";
$music_result=mysql_query($music_query);

while($mus=mysql_fetch_assoc($music_result)) {


$music_link="<embed src='members_music/".$mus["userfile_name"]."'  bgcolor='#A0C0F0' width='125' height='125' autostart='false' loop='false' >";
}

?>


[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.