woodsonoversoul Posted November 20, 2008 Share Posted November 20, 2008 Hi all, Firstly; I know that my code looks shabby. This is just a hobby project to see if I can create a multi-file upload script. The direction I'm trying to take is, initial information about a group of files -> a broken down list of each file with it's specific information(generated by the script, ie. new file names, etc.) and a place to select the file for upload -> the actual invisible upload script. My current problem is the second script/form doesn't access the upload script, but calls itself again with all the file information blank. Can you guys see why it's doing this? Initial File: archiver.php <html> <head> <title>Music Archiver</title> </head> <body> <form name="archive_input" action="array_processing.php" method="post"> <table> <tr><td><b>Enter Show Information:</b></td></tr> <tr> <td>Band:</td> <td><input type="text" name="band"></td> </tr> <tr> <td>Date:</td> <td><input type="text" name="date"></td> </tr> <tr> <td>Location:</td> <td><input type="text" name="loc"></td> </tr> <tr> <td>Set 1:</td> <td><textarea name="setOne" rows="4" cols="45"></textarea></td> </tr> <tr> <td>Set 2:</td> <td><textarea name="setTwo" rows="4" cols="45"></textarea></td> </tr> <tr> <td>Encore:</td> <td><input type="text" name="encore" size="39"></td> </tr> <tr><td></td> <td><input type="submit" value="Archive"> </tr> </table> </form> Intermediary file: array_processing.php <html> <head></head> <body> <?php /*function definitions*/ 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; $lcband = strtolower($band); switch($lcband) { 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; } 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 second row */ //split the object into a dummy array 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]); } //echo var_dump($dummy_array1); echo "<br>-------------------------<br>"; //then create the real 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(; } //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; } /*function upload(){ if(!is_uploaded_file($_FILES['upload_file']['tmp_name'])) { $error = "Please select the audio file"; } else { //This is the old code /* echo "File successfully uploaded!<br>"; echo "Some file information: <br>"; echo "You uploaded: $file_name <br>"; } if((!empty($_FILES['upload_file'])) && ($_FILES['upload_file']['error'] == 0)) { echo "file succsesfully uploaded!<br>"; copy($_FILES['upload_file']['tmp_name'],"/opt/lampp/htdocs/MNS/Music/".$_FILES['upload_file']['name']); unlink($_FILES['upload_file']['tmp_name']); } else{ echo "file not uploaded yet<br>";} //this is the new code from upload_script echo $_FILES[upload_file][name][$x]; if(!empty($_FILES[upload_file])){ // this will check if any blank field is entered $filename = $_FILES[upload_file][name]; // filename stores the value $filename=str_replace(" ","_",$filename);// Add _ inplace of blank space in file name, you can remove this line $add = "/home/dan/MusicDataBase/$filename"; // upload directory path is set //echo $_FILES[images][type][$key]; // uncomment this line if you want to display the file type // echo "<br>"; // Display a line break copy($_FILES[upload_file][tmp_name], $add); // upload the file to the server //chmod("$add",0777); // set permission to the file. unlink($_FILES[upload_file][tmp_name]); } } */ //declare variables pulling them from archiver.php //Initailize and assign values to starter variables. $show_id = ""; $band = $_POST['band']; echo "the band is $band<br>"; $date = $_POST['date']; echo "the date is $date<br>"; $setOne = $_POST['setOne']; echo "set one is $setOne <br>"; $setTwo = $_POST['setTwo']; echo "set two is $setTwo<br>"; $encore = $_POST['encore']; echo "the encore is $encore<br>"; echo "--------------------------------------<br>"; $unique_show_id = showIdCreator($band, $date); echo $unique_show_id; $set_one = create_song_array($setOne, $unique_show_id, "1"); echo var_dump($set_one); echo "<br>-----------------------------------<br>"; echo "<form>"; echo "<table>"; //Declare some global variables $header_array = array("unique song id", "song key", "song name", "part of a segue?", "special quest?", "extra comment", "file location"); echo "<form name=\"array_processing\" action=\"upload_script.php\" method=\"post\" enctype=\"multipart/form-data\">"; echo "<h1>Contents of array " . $unique_show_id . "</h1>"; echo "<table>"; for($m = 0; $m < 7; $m++){ echo "<tr> <th scope=\"row\">" . $header_array[$m] . "</th>"; for($i = 0; $i < count($set_one); $i++){ if ($m == 3) { echo "<td><input type=\"radio\" name=\"segue-" . $set_one[$i][$m] . "\"value=\"TRUE\" /> yes <input type=\"radio\" name=\"segue-" . $set_one_songs[$i][$m] . "\" value=\"FALSE\" /> no </td>"; } else if ($m == 6) { echo "<td><input type=\"file\" name=\"file-" . $set_one[$i][$m] . "\">"; echo "<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"209715200\">"; if(!is_uploaded_file($_FILES['file=' . $set_one[$i][$m]]['tmp_name'])) { echo "<br>Please select the audio file"; } else { echo "File successfully uploaded!<br>"; echo "Some file information: <br>"; echo "You uploaded: $file_name <br>"; } if((!empty($_FILES['file-' . $set_one[$i][$m]])) && ($_FILES['file-' . $set_one[$i][$m]]['error'] == 0)) { echo "file succsesfully uploaded!<br>"; copy($_FILES['file-' . $set_one[$i][$m]]['tmp_name'],"/home/dan/MusicDataBase/".$_FILES['file-' . $set_one[$i][$m]]['name']); unlink($_FILES['file-' . $set_one[$i][$m]]['tmp_name']); } echo "</td>"; } else{echo "<td><input type=\"text\" value=\"" . $set_one[$i][$m] . "\"</td>"; } } echo "</tr>"; } echo "<input type=\"submit\" value=\"Everything looks satisfactory! Begin upload\" /></p>"; echo"</table>"; echo"</form>"; ?> </body> </html> and finally, the upload script: upload_script.php <?php //set variables $x = 0; $set_one = $_POST['set_one']; $numOfFiles = count($set_one); while($x<$numOfFiles) { echo "numOfFiles = " . numOfFiles; echo $_FILES[upload_file][name][$x]; if(!empty($_FILES[upload_file])){ // this will check if any blank field is entered $filename = $_FILES[upload_file][name][$x]; // filename stores the value $filename=str_replace(" ","_",$filename);// Add _ inplace of blank space in file name, you can remove this line $add = "/home/dan/MusicDataBase/$filename"; // upload directory path is set //echo $_FILES[images][type][$key]; // uncomment this line if you want to display the file type // echo "<br>"; // Display a line break copy($_FILES[upload_file][tmp_name][$x], $add); // upload the file to the server //chmod("$add",0777); // set permission to the file. unlink($_FILES[upload_file][tmp_name][$x]); } $x++; } ?> Now again, I know this is very poor code (it's a first attempt) but I still feel like it should at least try to open upload_script.php or throw an error. Any ideas? Link to comment https://forums.phpfreaks.com/topic/133423-why-does-my-form-keep-calling-itself/ Share on other sites More sharing options...
btherl Posted November 20, 2008 Share Posted November 20, 2008 Try removing this line from array_processing.php: echo "<form>"; Forms can't nest, so that will probably take priority over any later form tags. Link to comment https://forums.phpfreaks.com/topic/133423-why-does-my-form-keep-calling-itself/#findComment-693984 Share on other sites More sharing options...
woodsonoversoul Posted November 20, 2008 Author Share Posted November 20, 2008 Awesome!! I commented that line out and it worked fine. Well, it didn't upload the file, but it did call upload_script.php. Thanks. Now to work out actually uploading files... Link to comment https://forums.phpfreaks.com/topic/133423-why-does-my-form-keep-calling-itself/#findComment-693988 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.