For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > November 2005 > Multiple Mp3 uploads









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Multiple Mp3 uploads
sectionFOURTEEN

2005-11-13, 6:56 pm

I have an upload script that works great except when uploading multiple
mp3 files. I can upload the following fine:

- multiple .wav, .gif, or .jpg files
- one .mp3 and multiple .wav, .gif, or .jpg files

When I try to upload more than one mp3 the script fails. I have no idea
why this would be happening. I'm uploading them my machine which is
running XP. I'm not specifying what type the file should be. Here's
part of the script:
----------------------------------------------
<?
//when you finally add the price parameter. format this
//so it requires purchase to be selected yes for the price.
if(isset($_POST['artist']) && ($_POST['title'])){
$purchase = $_POST['purchase'];
$artist = $_POST['artist'];
$title = $_POST['title'];
$info = $_POST['info'];
$cat = $_POST['cat'];
$type = $_POST['type'];
} else {
echo $purchase . $artist . $title . $info . $cat . $type;
echo "<br><br>" . count($_FILES['audio']['tmp_name']) . "<br><br>";
echo('<pre>');
print_r($_FILES['audio']['name']);
echo('</pre>');
die("All fields must be filled in. <a href='b_store2.php'>GO
BACK</a>");
}

//this is where the names of the tracks are put into the database
if(isset($_POST['tracks'])){
$tracks_array = $_POST['tracks'];
$tracks = implode("|",$tracks_array);
}else{
$tracks = "";
}
//for now image and price will be set manually
$image = "0G000.gif";
$price = "enter price later";

//this is where the track is uploaded to the tunes folder. Also
//the name of the track is uploaded to see if it should be a link on
the site
if($_POST['Submit']){

// directory Path edit with your own
$uploaddir = $_SERVER['DOCUMENT_ROOT'] . '/zero/tunes/';

for($i=0; $i<count($_FILES['audio']['tmp_name']); $i++){

// Upload data
$tempname = $_FILES['audio']['tmp_name'][$i];
$filename = $_FILES['audio']['name'][$i];

// Move file
if($tempname != ''){
move_uploaded_file($tempname, $uploaddir.$filename);
}

if(isset($_FILES['audio']['name'])){
$audio_array = $_FILES['audio']['name'];
$audio = implode("|",$audio_array);
}else{
$audio = "";
}
}

echo('<pre>');
print_r($_FILES['audio']['name']);
echo('</pre>');
----------------------------------------------------------------

What's weird is the first "if statement" is not working when I try to
upload multiple mp3's. So apparently artist and title aren't being set
when I try this. This makes no sense to me so any help would be greatly
appreciated

thanks,

Anthony

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com