Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 6 of 6
  1. #1
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    I have a bog standard form with 2 inputs. A File and a Submit button.

    When I click on the Browse button and select a file, when I close that dialog I want another file element to be displayed.

    Basically I am trying to create a multi file upload. If you have ever uploaded files via cpanel and you click "Add another upload box" or similar that is what I am trying to achieve.

    Currently the script does add a new file box, but outside of my form (so outside of my fieldset etc).

    Any ideas?

    I used http://www.matts411.com/webdev/creat...ith_javascript as a tutorial.

  2.  

  3. #2
    Senior Member hyperair's Avatar
    Join Date
    May 2005
    Posts
    452
    Member #
    9892
    Firstly, could you post the script you have in action?

    How about this:
    Code:
    // some code to figure out how many <input type="file"> elements there are
    // and save the number to variable "count".
    fileInput = document.createElement("input");
    fileInput.type = "file";
    fileInput.name = "file_" + count;
    document.form.SomeForm.appendChild(fileInput);
    Hyperair

  4. #3
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Thanks for the reply.

    What I did was, wrap the original file input box in a div #files. Then just made that the first parameter which is for the parent/container.

  5. #4
    Senior Member hyperair's Avatar
    Join Date
    May 2005
    Posts
    452
    Member #
    9892
    In that case this code should work right:
    Code:
    var files = document.getElementById('files');
    var count = files.getElementsByTagName('input').length;
    var fileInput = document.createElement("input");
    fileInput.type = "file";
    fileInput.name = "file_" + count;
    files.appendChild(fileInput);
    That way, you should have your file elements with names like these:
    file_0
    file_1
    file_2
    ...
    Hyperair

  6. #5
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    I am going argh! right now.

    I have the script adding fields as and when I need them. However they do not get sent along when I submit the form.

    So, I have stripped the form down to try and get it to work and for whatever reason the file will not appear in uploader.php when I print_r.

    What am I doing wrong?

    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
    
    	<title>Upload</title>
    
    </head>
    
    <body>
    
    	<form  enctype="multipart/form-data" action="uploader.php" method="POST">
    
    			<p><input type="file" name="file_[]" id="file_[]" /></p>
    
    			<p><input type="submit" name="submit" value="Upload" /></p>
    	</form>
    
    </body>
    </html>
    Oops. I was doing print_r($_POST) but files are in $_FILES. Is the fact that it is Monday any excuse?

  7. #6
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Just say `it's Memorial Day in the USA, and my brain accidentally took a break, too'


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 05:09 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com