upload multiple files----still waiting for your reply

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • deepaks85
    New Member
    • Aug 2006
    • 114

    upload multiple files----still waiting for your reply

    Dear Friends,

    I have post this query 4 days ago......but no one replied me.....

    I request you all to please help me on this........... ...

    I am trying to upload multiple files. But I can't find why it is not working fine. Here is the code.........

    numfile.php

    [HTML]<form method="POST" action="fileupl oad.php">
    <p align="center">
    <font face="Verdana" size="2">Number of files</font>
    <input type="text" class="text" name="numfiles" size="3" maxlength="3">< br>
    <br>
    <input type="submit" value="Submit" name="submit" style="font-family: Verdana; font-size: 8pt; font-weight: bold; border: 1px solid #666666; padding: 2"></p>
    </form>[/HTML]


    fileupload.php

    [PHP]
    $numoffile = $_POST['numfiles']; //value taking from numfile.php

    $file_dir = "files/";

    if ($_POST) {
    for ($i=0;$i<$numof file;$i++) {
    if (trim($_FILES['myfiles']['name'][$i])!="") {
    $newfile = $file_dir.$_FIL ES['myfiles']['name'][$i];
    move_uploaded_f ile($_FILES['myfiles']['tmp_name'][$i], $newfile);
    $j++;
    }
    }
    }
    if (isset($j)&&$j> 0) print "<center><f ont family='verdana ' size='2' color='green'>Y our file(s) has been uploaded.</font><br>";
    print "<p><h3 style='font-family:verdana; color:green;tex t-align:center'>U pload Files</h3></p><form method='post' enctype='multip art/form-data'>";
    for($i=0;$i<$nu moffile;$i++) {

    $num = $i+1;
    print "<center><s pan style='font-family:verdana; font-size:10pt'>File $num </span> <input type='file' name='myfiles[]' size='30'><br>" ;
    }
    print "<p align='center'> <input type='submit' name='action' value='Upload'> </p>";
    print "</form>"; [/PHP]




    Please help me out where is the error.........

    Thanks
    Deepak
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Erm... the error would be that there's no file input in your HTML, so nothing's getting uploaded.

    Comment

    • ak1dnar
      Recognized Expert Top Contributor
      • Jan 2007
      • 1584

      #3
      Try this coding and if you can't understand what i have done here come back to the thread.

      I have done some changes to these areas..

      1. hidden field.
      2. for loops
      3. form action

      [PHP]
      <?php
      $numoffile=$_PO ST['numfiles'];


      $file_dir = "files/";

      if ($_POST['action'])
      {
      for($x=1;$x<=$n umoffile;$x++)
      {
      $newfile = $file_dir.$_FIL ES['myfiles'.$x.'']['name'];
      move_uploaded_f ile($_FILES['myfiles'.$x.'']['tmp_name'],$newfile);
      $j++;
      }
      }

      if (isset($j)&&$j> 0)
      print "<center><f ont family='verdana ' size='2' color='green'>Y our file(s) has been uploaded.</font><br>";

      if($_POST['submit'])
      {
      print '<p><h3 style="font-family:verdana; color:green;tex t-align:center">U pload Files</h3></p>
      <form action="'.$PHP_ SELF.'" method="post" enctype="multip art/form-data">';

      for($i=0;$i<$nu moffile;$i++)
      {
      $num = $i+1;

      print '<center><span style="font-family:verdana; font-size:10pt">File $num </span>
      <input type="file" name="myfiles'. $num.'" size="30"><br>' ;

      }

      print '<p align="center"> <input type="hidden" name="numfiles" value="'.$numof file.'"><input type="submit" name="action" value="Upload"> </p>';

      print "</form>";
      }
      ?>
      [/PHP]

      Comment

      • ak1dnar
        Recognized Expert Top Contributor
        • Jan 2007
        • 1584

        #4
        oops i changed this line also.
        [PHP]<input type="file" name="myfiles[]" size="30">[/PHP]
        with this
        [PHP]<input type="file" name="myfiles'. $num.'" size="30">[/PHP]

        Comment

        Working...