I actually posted on here about a image upload script that you all so kindly helped with. Now I am using the same general concept of the image upload script to upload a MP3 file. I am not getting any errors it seems like it completes the script but nothing happens. No file is uploaded and no data is entered into the database. When I print_r() the file array it gives me the proper name, file size and mime type. I also comes back with a error code of 0. I can not figure out what is happening here.
Here is my script.
<?php
session_start();
error_reporting(E_ALL); ini_set("display_errors", "On");
include('functions.php');
$id = protect($_GET['id']);
$query = sprintf("SELECT * FROM artists WHERE user_id = %d",$id);
$res = mysql_query($query);
$row_a = mysql_fetch_assoc($res);
$totalRows_a = mysql_num_rows($res);
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?id=<?php echo $user_id ?>" method="post" enctype="multipart/form-data" id="something" class="uniForm">
<input name="upload" id="upload" size="30" type="file" class="fileUpload" />
<button name="submit" type="submit" class="submitButton">Upload</button>
<input name="artist_id" type="hidden" id="artist_id" value="<?php echo $row_a['artist_id']; ?>">
</form>
<?php
if(isset($_POST['submit'])){
$artist_id = $_POST['artist_id'];
$user_id = $_SESSION['user_id'];
if (isset ($_FILES['upload'])){
print_r($_FILES['upload']);
if ($_FILES['upload']['type'] !== "audio/mpeg"){
echo "You are only allowed to upload MP3 files";
if ($_FILES['upload'] == ""){
echo "You must select a file to upload";
}else{
$file = $_FILES['upload']['name'];
$ext = substr(strrchr($file, '.'), 1);
$rand = rand();
$name = $imagename . $rand;
$newname = md5($name).".".$ext;
$source = $_FILES['upload']['tmp_name'];
$target = "upload/".$newname;
move_uploaded_file($source, $target);
$filepath = $file;
$save = "upload/" . $newname; //This is the new file you saving
$file = "upload/" . $newname; //This is the original file
$mp3 = id3_get_tag( "uploads/$newname" );
extract($mp3);
echo "Artist: " . $artist . "<br />";
echo "Title: " . $title . "<br />";
$genre = id3_get_genre_name($genre);
echo "Genre: " . $genre;
$song_loc = "uploads/".$newname;
$sql = "INSERT into SONGS (user_id, artist_id, title, genre, song_loc) VALUES ('$user_id', '$artist_id', '$title', '$genre', '$song_loc')";
echo $sql;
$result = mysql_query($sql) or die ("Could not insert data into DB: " . mysql_error());
// if successfully updated.
if($result){
echo "Your Song: <a href='images/artists_images/".$newname."'>Click here to listen</a><br>";
}
else {
echo "ERROR with $query";
echo $mysql_error($query);
}
}
}
}
}
?>
</body>
</html>
Thank you in advance.

New Topic/Question
Reply




MultiQuote




|