Jump to content

uploading audio?


spires
 Share

Recommended Posts

Hi,

I posted earlyer and a few of you really pointed me in the right direction. 
But as usual, i'm stuck.

I have uploaded the mp3s to the server, and the id and date have been placed inside the database.
But, i cant seem to get the 'name' and 'userfile_name' to load into the database.

Can someone have a quick look at my code and point me in the right direction.  ;D
Thanks

[code]


<?php
include('db.php');


    echo '
<center>
  <table cellpadding="0" cellspacing="0" width="400" class="TLRB_border">
<tr>
<td align="center">

<strong>"All audio must be .mpeg files"</strong><br><br>
    <form method="POST" action="'.$_SERVER['PHP_SELF'].'" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="'.$_POST['320834100'].'">
<input type="hidden" name="id" value="'.$_POST['id'].'">
<input type="hidden" name="date_sent" value="'.$_POST['date_sent'].'">
<br>please choose a music file<br>
    <input type="file" name="userfile"><p>
    <input type="Submit" name="Submit" value="Submit">
    </form>
</td>
</tr>
</table><br>
</center>';



$query="select * from music 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='../index.php'>Update music</a><br><br>";
exit;
}
}




if(!isset($_FILES['userfile'])=="none") {
echo"no file specified<br><a href='upload.php'>please try again1</a><br><br>";
exit;
}


$uploaddir ="mp3/";
$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)) {

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

$id = $_POST['id'];
$userfile_name = $_POST['userfile_name'];
$name = $_POST['name'];


$userfile_name = addslashes($userfile_name);

$query="INSERT INTO music (id, name, date_sent, userfile_name) VALUES ('$id', '$name', '$date_sent', '$userfile_name')";

$result=mysql_query($query);

echo "file uploaded";

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


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

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



<?php

$music_query="SELECT * FROM music WHERE id='$id'";
$music_result=mysql_query($music_query);

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


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

?>
[/code]
Link to comment
Share on other sites

OK, Thanks

Explain please. i'm very new to PHP.

Quick question
How does the $_FILES read the name of the mp3?
How does it know what its callled and what part of the code does this?

I've only just started learning how to do this, and am not to shore how it all works yet.

Link to comment
Share on other sites

any better?

[code]
<link href="../css/nicky.css" rel="stylesheet" type="text/css">

<?php
include('db.php');


    echo '
<center>
  <table cellpadding="0" cellspacing="0" width="400" class="TLRB_border">
<tr>
<td align="center">

<strong>"All audio must be .mpeg files"</strong><br><br>
    <form method="POST" action="'.$_SERVER['PHP_SELF'].'" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="'.$_POST['320834100'].'">
<input type="hidden" name="name" value="'.$_POST['name'].'">
<input type="hidden" name="userfile_name" value="'.$_POST['userfile_name'].'">
<input type="hidden" name="id" value="'.$_POST['id'].'">
<input type="hidden" name="date_sent" value="'.$_POST['date_sent'].'">
<br>please choose a music file<br>
    <input type="file" name="userfile"><p>
    <input type="Submit" name="Submit" value="Submit">
    </form>
</td>
</tr>
</table><br>
</center>';



$query="select * from music 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='../index.php'>Update music</a><br><br>";
exit;
}
}




if(!isset($_FILES['userfile'])=="none") {
echo"no file specified<br><a href='upload.php'>please try again1</a><br><br>";
exit;
}


$uploaddir ="mp3/";
$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)) {

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

$id = $_POST['id'];
$userfile_name = $_POST['userfile_name'];
$name = $_POST['name'];


$userfile_name = addslashes($userfile_name);

$query="INSERT INTO music (id, name, date_sent, userfile_name) VALUES ('$id', '$name', '$date_sent', '$userfile_name')";

$result=mysql_query($query);

echo "file uploaded";

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


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

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



<?php

$music_query="SELECT * FROM music WHERE id='$id'";
$music_result=mysql_query($music_query);

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


$music_link="<embed src='mp3/".$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. Are you sure you have something important to add to it?

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.

 Share

×
×
  • 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.