How to access userfile names?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Don

    How to access userfile names?



    The following 4 statements don't work. What is the proper way to
    pickup the filenames corresponding to each of the userfiles in the
    "input" tags? Thanks for your help. --Don

    Following is part of a page that runs on the client side:
    -----------------------------------------------------------------
    var picture1 = document.forms. postamessagedat a.userfile.name[0];
    var picture2 = document.forms. postamessagedat a.userfile.name[1];
    var picture3 = document.forms. postamessagedat a.userfile.name[2];
    var picture4 = document.forms. postamessagedat a.userfile.name[3];

    Following is part of a form to be submitted to PHP upload processor
    below. This resides in the same page as the foregoing.
    --------------------------------------------------------------------------------
    <p>Optional picture #1:<br><input type=file name="userfile[]" size=90
    maxlength=20000 0 tabindex=3>;
    <p>Optional picture #2:<br><input type=file name="userfile[]" size=90
    maxlength=20000 0 tabindex=3>;
    <p>Optional picture #3:<br><input type=file name="userfile[]" size=90
    maxlength=20000 0 tabindex=3>;
    <p>Optional picture #4:<br><input type=file name="userfile[]" size=90
    maxlength=20000 0 tabindex=3>;

    Following processes file uploads and resides on server:
    -----------------------------------------------------------------
    <?php
    $uploaddir = 'picturevault/';
    $uploadfile1 = $uploaddir . $_FILES['userfile']['name'][0];
    $uploadfile2 = $uploaddir . $_FILES['userfile']['name'][1];
    $uploadfile3 = $uploaddir . $_FILES['userfile']['name'][2];
    $uploadfile4 = $uploaddir . $_FILES['userfile']['name'][3];

    print "<pre>";

    if ($_FILES['userfile']['size'][0] != 0)
    move_uploaded_f ile($_FILES['userfile']['tmp_name'][0],
    $uploadfile1);

    if ($_FILES['userfile']['size'][1] != 0)
    move_uploaded_f ile($_FILES['userfile']['tmp_name'][1],
    $uploadfile2);

    if ($_FILES['userfile']['size'][2] != 0)
    move_uploaded_f ile($_FILES['userfile']['tmp_name'][2],
    $uploadfile3);

    if ($_FILES['userfile']['size'][3] != 0)
    move_uploaded_f ile($_FILES['userfile']['tmp_name'][3],
    $uploadfile4);

    print "</pre>";

    ?>




    -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
    http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
    -----== Over 100,000 Newsgroups - 19 Different Servers! =-----
  • lallous

    #2
    Re: How to access userfile names?

    Hello

    You will find this useful:

    <html>
    <head>
    <title> New Document </title>
    <meta name="Generator " content="EditPl us">
    <meta name="Author" content="lallou s">
    <meta name="Keywords" content="">
    <meta name="Descripti on" content="">
    </head>

    <script language="JavaS cript">
    <!--
    function f1()
    {
    var f = document.f, e, s = '';
    for (i=0;i<f.elemen ts.length;i++)
    {
    e = f.elements[i];
    x = e.name;
    e = f.elements[i];
    s += "i=" + i + " elements name='" + x + "' element value='" + e.value +
    "'\n";
    }
    alert(s);
    }
    //-->
    </script>
    <body onload="f1();">
    <form name="f">
    <input type="text" name="f_t[]" value="1">
    <input type="text" name="f_t[]" value="2">
    <input type="text" name="f_t[]" value="3">
    <input type="text" name="f_t[]" value="4">
    </body>
    </html>


    p.s: you may replace the type="text" w/ type="file".
    And to access its value you do it as: elementName.val ue.

    --
    Elias

    "Don" <no@adr.com> wrote in message
    news:lkdfl0pu91 ugs64e7dkbbp70r bm6ckvnr3@4ax.c om...[color=blue]
    >
    >
    > The following 4 statements don't work. What is the proper way to
    > pickup the filenames corresponding to each of the userfiles in the
    > "input" tags? Thanks for your help. --Don
    >
    > Following is part of a page that runs on the client side:
    > -----------------------------------------------------------------
    > var picture1 = document.forms. postamessagedat a.userfile.name[0];
    > var picture2 = document.forms. postamessagedat a.userfile.name[1];
    > var picture3 = document.forms. postamessagedat a.userfile.name[2];
    > var picture4 = document.forms. postamessagedat a.userfile.name[3];
    >
    > Following is part of a form to be submitted to PHP upload processor
    > below. This resides in the same page as the foregoing.
    > --------------------------------------------------------------------------------
    > <p>Optional picture #1:<br><input type=file name="userfile[]" size=90
    > maxlength=20000 0 tabindex=3>;
    > <p>Optional picture #2:<br><input type=file name="userfile[]" size=90
    > maxlength=20000 0 tabindex=3>;
    > <p>Optional picture #3:<br><input type=file name="userfile[]" size=90
    > maxlength=20000 0 tabindex=3>;
    > <p>Optional picture #4:<br><input type=file name="userfile[]" size=90
    > maxlength=20000 0 tabindex=3>;
    >
    > Following processes file uploads and resides on server:
    > -----------------------------------------------------------------
    > <?php
    > $uploaddir = 'picturevault/';
    > $uploadfile1 = $uploaddir . $_FILES['userfile']['name'][0];
    > $uploadfile2 = $uploaddir . $_FILES['userfile']['name'][1];
    > $uploadfile3 = $uploaddir . $_FILES['userfile']['name'][2];
    > $uploadfile4 = $uploaddir . $_FILES['userfile']['name'][3];
    >
    > print "<pre>";
    >
    > if ($_FILES['userfile']['size'][0] != 0)
    > move_uploaded_f ile($_FILES['userfile']['tmp_name'][0],
    > $uploadfile1);
    >
    > if ($_FILES['userfile']['size'][1] != 0)
    > move_uploaded_f ile($_FILES['userfile']['tmp_name'][1],
    > $uploadfile2);
    >
    > if ($_FILES['userfile']['size'][2] != 0)
    > move_uploaded_f ile($_FILES['userfile']['tmp_name'][2],
    > $uploadfile3);
    >
    > if ($_FILES['userfile']['size'][3] != 0)
    > move_uploaded_f ile($_FILES['userfile']['tmp_name'][3],
    > $uploadfile4);
    >
    > print "</pre>";
    >
    > ?>[/color]


    Comment

    • Grant Wagner

      #3
      Re: How to access userfile names?

      lallous wrote:
      [color=blue]
      > Hello
      >
      > You will find this useful:
      >
      > <html>
      > <head>
      > <title> New Document </title>
      > <meta name="Generator " content="EditPl us">
      > <meta name="Author" content="lallou s">
      > <meta name="Keywords" content="">
      > <meta name="Descripti on" content="">
      > </head>
      >
      > <script language="JavaS cript">[/color]

      <script type="text/javascript">

      The language attribute is deprecated.
      [color=blue]
      > <!--[/color]

      Not required or desired.
      [color=blue]
      > e = f.elements[i];
      > x = e.name;
      > e = f.elements[i];[/color]

      I'm not sure why you're grabbing a reference to the form element twice.
      [color=blue]
      > //-->[/color]

      Not required or desired.
      [color=blue]
      > </script>
      > <body onload="f1();">
      > <form name="f">[/color]

      You are missing a closing </form> tag.
      [color=blue]
      > </body>
      > </html>[/color]

      <form>
      <p>Optional picture #1:<br><input type=file name="userfile[]" size=90
      maxlength=20000 0 tabindex=3>;
      <p>Optional picture #2:<br><input type=file name="userfile[]" size=90
      maxlength=20000 0 tabindex=3>;
      <p>Optional picture #3:<br><input type=file name="userfile[]" size=90
      maxlength=20000 0 tabindex=3>;
      <p>Optional picture #4:<br><input type=file name="userfile[]" size=90
      maxlength=20000 0 tabindex=3>;

      Read the values with:
      <input type="button"
      value="Show picture names (example only)"
      onclick="showIn putValuesOf(thi s.form, 'userfile[]');">
      </form>

      <script type="text/javascript">
      function showInputValues Of(f, inputName) {
      var output = [];
      var inputs = f.elements[inputName];
      if (typeof inputs.length == 'undefined') {
      inputs = [ inputs ];
      }
      for (var i = 0; i < inputs.length; i++) {
      output.push(inp uts[i].value);
      }
      alert(output.jo in('\n'));
      }
      </script>

      --
      Grant Wagner <gwagner@agrico reunited.com>
      comp.lang.javas cript FAQ - http://jibbering.com/faq

      Comment

      Working...