drisate Posted May 14, 2008 Share Posted May 14, 2008 Hey guys i am having a problem making an upload script where you can click on a button and it adds a new form field. That part works well but the PHP scrip handling them returns emtpy stuff. <form name='etape3' method='POST' action='catalogue.php?mod=13&id=$id&send=1' enctype='multipart/form-data'> <script type="text/javascript"> var fields; function HTMLBlock(el) { var instance = 1, elementNames = [], i, item, container; /* remove source element */ container = el.parentNode; container.removeChild(el); /* cache input elements' name attributes */ for (i = 0; item = el.getElementsByTagName("input").item(i); i++) { elementNames[i] = item.getAttributeNode("name"); } /* method to modify and insert a clone of the original element */ this.insert = function () { for (var i = elementNames.length; i--; ) { /* replace digits with instance # */ elementNames[i].nodeValue = elementNames[i].nodeValue.replace(/\d+/, instance); } instance++; container.appendChild(el.cloneNode(true)); }; } function createHTMLBlock(id) { var d = document, el; /* test browser supports the methods we'll be using */ if (d.getElementById && (el = d.getElementById(id)) && el.getElementsByTagName && el.cloneNode && el.getAttributeNode) { /* ... etc. */ return new HTMLBlock(el); // yes } return null; // no } function addHTML() { if (fields) { fields.insert(); } } </script> <center><input type="button" onclick="addHTML()" value="Add Fields"></center><br> <div id="new_link_fields"><div id="form_source"><span class="r">Nom: <input type='text' name='nom[]' value='' size='20'><input type='hidden' name='i[]' value='1'> <input type='file' name='mp3[]' size='30'><br></span></div></div> <script type="text/javascript"> /* remove the HTML and set up the object down here, before anything's displayed */ fields = createHTMLBlock("form_source"); </script> </form> The php stuff i use foreach ($_POST["mp3"] as $eachInput) {$nb++;} // Debug line //echo "We are taking care of $nb loops"; for($i=0; $i != $nb ; $i++) { $file_name = $_FILES['mp3_'.$i]['name']; $file_tmp = $_FILES['mp3_'.$i]['tmp_name']; echo "<br><br><b>This is loop $i</b><br>"; echo "<b>The name of the file is $file_name</b><br>"; echo "<b>The var is mp3_$i</b><br><br>"; //Ici je regarde si l'extantion du code est autoriser $ext = strrchr($_FILES['mp3_'.$i]['name'],'.'); if (($extlimit == "OUI") && (!in_array($ext,$limitedext))) { echo "Le MP3 num $i n'a pas un extension autoriser. (mp3 seulement)<br>"; }else{ // Ici je regarde si le fichier existe déjà. if(file_exists($upload_dir.$_FILES['mp3_'.$i]['name'])){ $random_digit=rand(0000,9999)."_"; }else{unset($random_digit);} if (move_uploaded_file($file_tmp,$_SERVER['DOCUMENT_ROOT']."/admin/site/".$upload_dir.$random_digit.$_FILES['mp3_'.$i]['name'])){ chmod($_SERVER['DOCUMENT_ROOT']."/admin/site/".$upload_dir.$random_digit.$_FILES['mp3_'.$i]['name'], 0755); $mp3 = new mp3($upload_dir.$random_digit.$_FILES['mp3_'.$i]['name']); $mp3_1 = $mp3->extract(0,30); $newname=rand("100000", "999999")."_"; $mp3_1->save($upload_demo_dir.$newname.$random_digit.$_FILES['mp3_'.$i]['name']); $insert=mysql_query("INSERT INTO `distadp_adpsite`.`artiste_mp3` (id, nom_mp3, nom_demo, num_albume, nom)VALUES (NULL , '".$random_digit.$_FILES['mp3_'.$i]['name']."', '".$newname.$random_digit.$_FILES['mp3_'.$i]['name']."', '$_GET[id]', '".$_POST['nom_'.$i]."')"); echo "<br>MP3 numéro $i uploadé! (<a href='http://distributionadp.info/admin/site/$upload_dir$random_digit".$_FILES['mp3_'.$i]['name']."'>".$_FILES['mp3_'.$i]['name']."</a>)<br>"; echo "Démo de 30 sec créé avec succès! (<a href='http://distributionadp.info/admin/site/$upload_demo_dir$newname$random_digit".$_FILES['mp3_'.$i]['name']."'>$newname".$_FILES['mp3_'.$i]['name']."</a>)<br><br>"; }else{ echo "Il ya eu une éreure inconnu dans le transfère du fichier du mp3 num $i (".$_FILES['mp3_'.$i]['name'].")<br>"; } } } And this script returns this This is loop 0 The name of the file is The var is mp3_0 Le MP3 num 0 n'a pas un extension autoriser. (mp3 seulement) This is loop 1 The name of the file is The var is mp3_1 Le MP3 num 1 n'a pas un extension autoriser. (mp3 seulement) This is loop 2 The name of the file is The var is mp3_2 Le MP3 num 2 n'a pas un extension autoriser. (mp3 seulement) The name of the files are empty so it's obviously not taking care of the uploaded stuff ... Any help on this would be greatly appreciated Quote Link to comment https://forums.phpfreaks.com/topic/105616-uploaded-files-are-not-uploaded-o0/ Share on other sites More sharing options...
shedokan Posted May 14, 2008 Share Posted May 14, 2008 put this in catalouge page and give me the out put: print_r($_POST); Quote Link to comment https://forums.phpfreaks.com/topic/105616-uploaded-files-are-not-uploaded-o0/#findComment-541129 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.