Jump to content


Photo

uploading audio?


  • Please log in to reply
4 replies to this topic

#1 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 17 July 2006 - 10:04 PM

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



<?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' >";
}

?>

How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 17 July 2006 - 10:08 PM

Your form has no element named 'name' so this... $name = $_POST['name']; is redundant.

ps: What editor are you using? Those tabs are anoyingly difficult to read.

#3 pixy

pixy
  • Members
  • PipPipPip
  • Advanced Member
  • 295 posts

Posted 17 July 2006 - 10:10 PM

^ Agreed about the tabs--they're slightly ridiculous to look at. It seems a lot of people have been posting code that's just all over the map and completely unorginized. O_O

This is a .44 Caliber Loveletter straight through my heart.

Tabulas + Threadless + Hire Me!


#4 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 17 July 2006 - 10:12 PM

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.


How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com

#5 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 17 July 2006 - 10:24 PM

any better?

<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' >";
}

?>

How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users