Jump to content

Recommended Posts

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...

<?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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.