searls03 Posted May 25, 2011 Share Posted May 25, 2011 how do I make document upload fields like the ones that are on this website where there is a link at the bottom to make another field appear, or make it so that a new field automatically appears when the first one has info in it. Does this make sense? and also how would i make these submit with the form seeing as that they would have different field names, wouldn't they? Quote Link to comment https://forums.phpfreaks.com/topic/237385-document-upload-form/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 25, 2011 Share Posted May 25, 2011 The field is added (appended to the DOM document in the browser) using javascript. There are a TON of 'javascript dynamically add form field' scripts posted all over the Internet. You would use an array name for the form field name="..." attribute and simply loop over the resulting $_FILES array in the form processing code. See Example #3 at this link - http://us.php.net/manual/en/features.file-upload.post-method.php Quote Link to comment https://forums.phpfreaks.com/topic/237385-document-upload-form/#findComment-1219834 Share on other sites More sharing options...
searls03 Posted May 25, 2011 Author Share Posted May 25, 2011 would that also be what I could use to make it so a new one automatically pops up? Quote Link to comment https://forums.phpfreaks.com/topic/237385-document-upload-form/#findComment-1219836 Share on other sites More sharing options...
searls03 Posted May 25, 2011 Author Share Posted May 25, 2011 could you help me turn this into a correct array? I am new to arrays....thanks: <?php // Where the file is going to be placed $target_path = "secure/upload/"; /* Add the original filename to our target path. Result is "uploads/filename.extension" */ $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/237385-document-upload-form/#findComment-1219838 Share on other sites More sharing options...
searls03 Posted May 25, 2011 Author Share Posted May 25, 2011 how can I make it so that a new field will pop up when the field has value, the new one will come up? then same thing for the one after that, and after that, etc. here is the code I found: <script> var counter = 1; var limit = 10; function addInput(divName){ if (counter == limit) { alert("You have reached the limit of adding " + counter + " inputs"); } else { var newdiv = document.createElement('div'); newdiv.innerHTML = "<br><input type='file' name='uploadedfile[]'>"; document.getElementById(divName).appendChild(newdiv); counter++; } } </script> Quote Link to comment https://forums.phpfreaks.com/topic/237385-document-upload-form/#findComment-1220282 Share on other sites More sharing options...
searls03 Posted May 30, 2011 Author Share Posted May 30, 2011 did that make sense? Quote Link to comment https://forums.phpfreaks.com/topic/237385-document-upload-form/#findComment-1222624 Share on other sites More sharing options...
searls03 Posted June 1, 2011 Author Share Posted June 1, 2011 any help at all? Quote Link to comment https://forums.phpfreaks.com/topic/237385-document-upload-form/#findComment-1223510 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.