warhead2020 Posted April 8, 2009 Share Posted April 8, 2009 I have this problem first.php <code> <script language="javascript" > function addElement() { var ni = document.getElementById('myDiv'); var numi = document.getElementById('theValue'); var num = (document.getElementById('theValue').value -1 + 2); numi.value = num; var newdiv = document.createElement('div'); var divIdName = 'my'+num+'Div'; newdiv.setAttribute('id',divIdName); newdiv.innerHTML = '<input type=file id=imgfile' + num + ' name=imgfile' + num + '><a href="javascript:remove('+divIdName+')">Remove</a>'; ni.appendChild(newdiv); } function remove(dId) { var ni = document.getElementById('myDiv'); var numi = document.getElementById('theValue'); var num = (document.getElementById('theValue').value -1 + 0); numi.value = num; ni.removeChild(dId); } </script> <form name="frmUp" method="post" action="second.php"> <p><a href="javascript:addElement()" >Add Upload Field</a></p> <p> <input type="hidden" value="0" id="theValue" name="theValue"/> </p> <table width="100%" border="0"> <tr> <td> <div id="myDiv"> </div> </td> </tr> <tr> <td><label> <input type="submit" name="button" id="button" value="Submit" /> </label></td> </tr> </table> <div id="myDiv"> </div> </form> </code> second.php <code> $theValue = $_REQUEST['theValue']; echo "theValue " . $theValue; for($i = 1;$i <= $theValue;$i++) { echo basename($_FILES['imgfile' . $i]['name']); } </code> in the first.php file, i use javascript to create input dynamically. But the problem is, i can grab the "theValue" value but i cant grab the "basename($_FILES['imgfile' . $i]['name'])". I hope somebody out there can understand this and help me solve this problem. Thanx in advance. Link to comment https://forums.phpfreaks.com/topic/153126-upload-picture-problem/ Share on other sites More sharing options...
Yesideez Posted April 8, 2009 Share Posted April 8, 2009 Please edit your post and surround the code with CODE tags. Makes it more readable as it preserves the formatting. Link to comment https://forums.phpfreaks.com/topic/153126-upload-picture-problem/#findComment-804324 Share on other sites More sharing options...
warhead2020 Posted April 8, 2009 Author Share Posted April 8, 2009 Please edit your post and surround the code with CODE tags. Makes it more readable as it preserves the formatting. sorry...im new here..not sure how to use the code tag Link to comment https://forums.phpfreaks.com/topic/153126-upload-picture-problem/#findComment-804329 Share on other sites More sharing options...
Axeia Posted April 8, 2009 Share Posted April 8, 2009 use square brackets instead of round ones [ code] [/ code] (without the spaces) And surround your code with <?php ?> to enable syntax highlighting, so [ code]<?php //Your code ?>[/ code] <?php //Your code ?> Link to comment https://forums.phpfreaks.com/topic/153126-upload-picture-problem/#findComment-804334 Share on other sites More sharing options...
Yesideez Posted April 8, 2009 Share Posted April 8, 2009 Hey no probs As Axeia said - there's also the PHP tags you can use if your source doesn't have <?php and ?> in it: echo 'hello'; Use them the same as the CODE tags. Link to comment https://forums.phpfreaks.com/topic/153126-upload-picture-problem/#findComment-804335 Share on other sites More sharing options...
warhead2020 Posted April 8, 2009 Author Share Posted April 8, 2009 I have this problem first.php <script language="javascript" > function addElement() { var ni = document.getElementById('myDiv'); var numi = document.getElementById('theValue'); var num = (document.getElementById('theValue').value -1 + 2); numi.value = num; var newdiv = document.createElement('div'); var divIdName = 'my'+num+'Div'; newdiv.setAttribute('id',divIdName); newdiv.innerHTML = '<input type=file id=imgfile' + num + ' name=imgfile' + num + '><a href="javascript:remove('+divIdName+')">Remove</a>'; ni.appendChild(newdiv); } function remove(dId) { var ni = document.getElementById('myDiv'); var numi = document.getElementById('theValue'); var num = (document.getElementById('theValue').value -1 + 0); numi.value = num; ni.removeChild(dId); } </script> <form name="frmUp" method="post" action="second.php"> <p><a href="javascript:addElement()" >Add Upload Field</a></p> <p> <input type="hidden" value="0" id="theValue" name="theValue"/> </p> <table width="100%" border="0"> <tr> <td> <div id="myDiv"> </div> </td> </tr> <tr> <td><label> <input type="submit" name="button" id="button" value="Submit" /> </label></td> </tr> </table> <div id="myDiv"> </div> </form> second.php <?php $theValue = $_REQUEST['theValue']; echo "theValue " . $theValue; for($i = 1;$i <= $theValue;$i++) { echo basename($_FILES['imgfile' . $i]['name']); } ?> in the first.php file, i use javascript to create input dynamically. But the problem is, i can grab the "theValue" value but i cant grab the "basename($_FILES['imgfile' . $i]['name'])". I hope somebody out there can understand this and help me solve this problem. Thanx in advance. Link to comment https://forums.phpfreaks.com/topic/153126-upload-picture-problem/#findComment-804357 Share on other sites More sharing options...
warhead2020 Posted April 8, 2009 Author Share Posted April 8, 2009 I have found the REAL PROBLEM...!! I forgot to add this line .. ENCTYPE="multipart/form-data" in the form tag. PROBLEM SOLVED!... SORRY FOR ANY INCONVIENCE Link to comment https://forums.phpfreaks.com/topic/153126-upload-picture-problem/#findComment-804640 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.