Page 1 of 1

need some help with an uploading script

Posted: Fri Dec 05, 2003 9:04 pm
by JoeFritz
http://groupsounds.net/mp3upload.php

on that page i use this code to upload mp3 files and input information about them into a database. for some reason a lot of people are getting error: 0 out of it. which is code for "no error" so it should have worked but it didn't. here's the code i used. let me know if i made some kind of stupid beginner mistake (i know my code is sloppy, i'm a newbie):

Code: Select all

if ($_POST['op'] == 'up') {
	$uploaddir = '/home/gsound/public_html/mp3/';
	$filename = $_FILES['userfile']['name'];
	$uploadfile = $uploaddir . $filename;
	$genre = $_POST['genre'];
	$description = $_POST['description'];



print "<pre>";
 if ($_FILES['userfile']['type'] !== 'audio/mpeg') {
  echo "Error no. " . $_FILES['userfile']['error'];
	echo "<a href='mp3upload.php'>[try again]</a>";
  //echo $_FILES['userfile']['filetype'];
 } elseif (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) { 
 $insert_data = "INSERT INTO mp3 (filename,username,description,title,genre,band ) 
 							   VALUES ("" . $filename . "","" . $user . "","" . $description . "","" . $title . "","" . $genre . "","" . $row['alias'] . "")";
	@mysql_query($insert_data) or die("Couldn't insert data.");
 
  echo "<font face='times'>upload sucessful.</font>";
  echo "<br><br><font face='times'><a href='home.php' target='_parent'>[refresh]</a></font>";
 } else {
     print "error uploading file";
 }
 print "</pre>";
} else {

	echo "<b>maximum size 5 megabytes</b>";
	echo "<form enctype="multipart/form-data" action="mp3upload.php" method="POST">";
	echo "<input type="hidden" name="MAX_FILE_SIZE" value="5000000">";
	echo "<input type="hidden" name="op" value="up">";
	echo "select your mp3:<br><input name="userfile" type="file" size="15"><br>";
	echo "song title: <br>"; 
	echo "<input name="title" size="29" type="text"><br>";
thanks for whatever help you can give me. i know this may be hard to read.

Posted: Fri Dec 05, 2003 9:15 pm
by infolock
on this

Code: Select all

if ($_FILES['userfile']['type'] !== 'audio/mpeg') { 
  echo "Error no. " . $_FILES['userfile']['error']; 
   echo "<a href='mp3upload.php'>[try again]</a>"; 
  //echo $_FILES['userfile']['filetype']; 
} elseif (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
try this :

Code: Select all

if ($_FILES['userfile']['type'] !== 'audio/mpeg') { 
  echo "Error no. " . $_FILES['userfile']['error']; 
   echo "<a href='mp3upload.php'>[try again]</a>"; 
   exit;  // just exit the script if an error occurs.
  //echo $_FILES['userfile']['filetype']; 
} 
// don't need ELSEIF , just use IF since the first IF will die if it's true, and this one will be processed if it's false.
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {