Jump to content

Archived

This topic is now archived and is closed to further replies.

spires

Uploading mp3s to database or server?

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

Share this post


Link to post
Share on other sites
Yes. Anything can be uploaded. I prefer to store the files in the OS, and the paths in the database.

Share this post


Link to post
Share on other sites
do you know of any good articles on this?

as every time i type anything to do with mp3s in to google, it comes back with torrent sites.

Cheers

Share this post


Link to post
Share on other sites
A typical upload tutorial should suit your needs. The customizations are that you're looking for different extensions (.mp3) and different file types (audio/mp3).

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

×

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.