woodsonoversoul Posted December 9, 2008 Author Share Posted December 9, 2008 Give me just a second... Yes! It made a great deal of difference. The script now uploads the first file but not the second (which is much better than uploading no files, as was the case before), so now I'll start looking at the for loops... Quote Link to comment https://forums.phpfreaks.com/topic/135610-solved-multi-file-upload-script/page/2/#findComment-710097 Share on other sites More sharing options...
woodsonoversoul Posted December 9, 2008 Author Share Posted December 9, 2008 Update: I tried it with three files and it only uploads the first... Quote Link to comment https://forums.phpfreaks.com/topic/135610-solved-multi-file-upload-script/page/2/#findComment-710100 Share on other sites More sharing options...
gevans Posted December 9, 2008 Share Posted December 9, 2008 do you get an error or does it just stop? Quote Link to comment https://forums.phpfreaks.com/topic/135610-solved-multi-file-upload-script/page/2/#findComment-710101 Share on other sites More sharing options...
gevans Posted December 9, 2008 Share Posted December 9, 2008 <?php #File uploading script ////////////////////////////////////////////////////////////////// //the following are my functions which may or may not work //their main function is to bring data from archiver.html //and run various splitting and tagging functions on it //aside from the functions included here, everything //works perfectly ////////////////////////////////////////////////////////////////// ////////////////functions//////////////////// function create_song_array($set, $unique_show_id, $set_num) {   /*function takes in show.set object, splits that object into   an array, and then makes it multidiminsional. It then creates and   assigns song ids to the first row of the array and song titles   to the third row */   //split the object into a dummy array based on ',' and '>', using perl-type regex   $dummy_array = preg_split("/(,|>)/", $set);   //use the trim() function to remove leading/trailing white spaces   for($i=0;$i<count($dummy_array);$i++){     $dummy_array[$i] = trim($dummy_array[$i]);   }   //then create the real array as a copy of dummy array   $song_array = array(count($dummy_array));   //make the real array multidiminsional and create eight   //rows to hold the song's various properties   for($i = 0; $i < count($dummy_array); $i++){     $song_array[$i] = array(;   }   //assign song title, set_one_songs[2] = dummy_array[1]   for($m = 0; $m < count($dummy_array); $m++){     $song_array[$m][2] = $dummy_array[$m];   }   //assign unique song ids   for($n = 0; $n < count($dummy_array); $n++) {     $song_array[$n][0] = $unique_show_id . "s" . $set_num . "s" . ($n+1);   }   //return newly created array   return $song_array; }//create_song_array function showIdCreator($band, $date) {   /*this function takes in the user inputed band name and show date.   It then produces an abbreviation from the band name.   It then returns this abbreviation combined with the show date   to create the show id*/   //variable declarations   $abb;//store the abbreviated band name   //convert the band name to lower case for easier comparison   $band = strtolower($band);   //set abbreviation based on band name   switch($band) {     case "widespread panic" :       $abb = "wsp";       break;     case "grateful dead" :       $abb = "gd";       break;     case "phish" :       $abb = "ph";       break;     case "ryan adams" :       $abb = "ra";       break;     default:     $abb = "unknown";   }   //return a combination of the band name abbreviation and the show date   return $abb . $date; }//end showIdCreator() ////////////////end of functions//////////////////// function printHead(){   echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">          <html xmlns="http://www.w3.org/1999/xhtml"       xml:lang="en" lang="en">       <head>    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />       <title>File Uploader</title>    <style type="text/css" title ="text/css" media="all">    .error {      font-weight: bold;      color: #C00    }    </style>    </head>    <body>'; }  //turn on error reporting ini_set('display_errors', 'On'); error_reporting(E_ALL | E_STRICT); printHead(); #print html head //Initailize and assign values to starter variables. $show_id = ""; $band = $_POST['band']; $date = $_POST['date']; $setOne = $_POST['setOne']; //create a unique show id $unique_show_id = showIdCreator($band, $date); //create an array of songs based on set on and save it to an array of the same name $set_one = create_song_array($setOne, $unique_show_id, "1"); //check to see if file has been submitted if(isset($_POST['submitted'])){   //start a loop to move through all the files   for($i = 0; $i < count($_FILES['upload']['name']); $i++){     //if it has, check the type     //debug - show all pertinate file info     /*echo "<pre>";     print_r($_FILES);     echo "</pre>";*/     //create an array of allowed types (NOTE: need MIME type for Flac)     $allowed = array('audio/mpeg');         //now evaluate current file     //check to see if current file's type is in the array of allowed types     if(in_array($_FILES['upload']['type'][$i], $allowed)){       //If True, move the file to new location       if(move_uploaded_file($_FILES['upload']['tmp_name'][$i], "/home/dan/MusicDataBase/{$_FILES['upload']['name'][$i]}")){         echo '<p><em>The file has been uploaded!</em></p>';         //Delete file if if still exist         if(file_exists($_FILES['upload']['tmp_name'][$i]) && is_files($_FILES['upload']['tmp_name'][$i])){           unlink($_FILES['upload']['tmp_name'][$i]);         }       } else {         if($_FILES['upload']['error'][$i] > 0){           echo '<p class="error">The file could not be uploaded because: <strong>';           //print message based on error           switch($_FILES['upload']['error'][$i]){             case 1:               print 'The file exceeds the upload_max_filesize settiing in php.ini';               break;             case 2:               print 'The file exceeds the MAX_FILE_SIZE setting in the html form';               break;             case 3:               print 'The file was only partially uploaded';               break;             case 4:               print 'No file was uploaded';               break;             case 6:               print 'No temporary folder was available';               break;             case 7:               print 'Unable to write to the disk';               break;             case 8:               print 'File upload was stopped';               break;             default:               print 'A system error occured';               break;           }//end of switch           print '</strong></p>';         }//end of error if       }     } else {//invaild type       echo '<p class="error">Error: Wrong filetype. Must be mp3</p>';     }//end else   } }//end for loop //display show information echo "The band is: " . $band . "<br>"; echo "The show date is: " . $date . "<br>"; echo "Unique show id: " . $unique_show_id . "<br><br>"; ?> <form enctype="multipart/form-data" action="upload_script.php" method="post"> <?php //use a for loop to produce multiple upload boxes for($i = 0; $i < count($set_one); $i++){  ?> <input type ="hidden" name = "MAX_FILE_SIZE" value = "209715200" /> <fieldset><legend>Select a mp3 to upload:</legend> <p><b>file:</b><input type="file" name ="upload[]" /></p> </fieldset> <?php //end for loop } ?> <div align="center"><input type="submit" name="submit" value="Submit" /></div> <input type="hidden" name="submitted" value="TRUE" /> </form> </body> </html>  Try that! Quote Link to comment https://forums.phpfreaks.com/topic/135610-solved-multi-file-upload-script/page/2/#findComment-710103 Share on other sites More sharing options...
woodsonoversoul Posted December 9, 2008 Author Share Posted December 9, 2008 AHHH!! It works!! Thank you so much gevans! I've been working on this off and on for about six months, and now I finally have a working script. Thank you. Â Dan Quote Link to comment https://forums.phpfreaks.com/topic/135610-solved-multi-file-upload-script/page/2/#findComment-710109 Share on other sites More sharing options...
woodsonoversoul Posted December 9, 2008 Author Share Posted December 9, 2008 Why did including the ['name'] field in the for loop help? Quote Link to comment https://forums.phpfreaks.com/topic/135610-solved-multi-file-upload-script/page/2/#findComment-710111 Share on other sites More sharing options...
gevans Posted December 9, 2008 Share Posted December 9, 2008 if you count $_FILES['uploaded'] it will count the next arrays (multi dimensional array) Â which I believe will always result in 5 Quote Link to comment https://forums.phpfreaks.com/topic/135610-solved-multi-file-upload-script/page/2/#findComment-710113 Share on other sites More sharing options...
woodsonoversoul Posted December 9, 2008 Author Share Posted December 9, 2008 Okay, that makes sense, but I never would have figured it out on my own. Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/135610-solved-multi-file-upload-script/page/2/#findComment-710127 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.