Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/237385-document-upload-form/
Share on other sites

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

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!";
}


?>

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>

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.