multiple images uploader

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sajjad525
    New Member
    • Aug 2009
    • 5

    multiple images uploader

    Any one please help me :i have upload the multiple image on server but i have problem to save the name of these image's name my code as following ...
    (test1.php)
    Code:
    <?
      include_once('connection_db.php');
      $username=$_REQUEST['name'];
      $index=$_REQUEST['cboxcata'];
      if($_REQUEST){
      for($i=1;$i<3;$i++){
      $filename= $_FILES["userfile"]["name"][$i];
       			move_uploaded_file($_FILES["userfile"]["tmp_name"][$i], "../upload/".$filename);
    			
        
       }
      	$q="insert into person(image)values('$filename')";
    	
     	 $r=mysql_query($q);
    	 header("location:test.php");
    	 
    }
      
    
    ?>
    htlm file is:
    <form name="" action="test1.php" method="post" enctype="multipart/form-data">
    
      <table width="350" border="0" align="center">
        <tr>
          <td colspan="2" align="center"><?=$msg?></td>
        </tr>
        
        <tr>
          <td align="left">Image1:</td>
          <td align="left"><input type="file" name="userfile[1]" /></td>
        </tr>
        <tr>
          <td align="left">Image2:</td>
          <td align="left"><input type="file" name="userfile[2]" /></td>
        </tr>
        <!--<tr>
          <td align="left">Image3:</td>
          <td align="left"><input type="file" name="userfile[]" /></td>
        </tr>
        <tr>
          <td align="left">Image4:</td>
          <td align="left"><input type="file" name="userfile[]" /></td>
        </tr>
        <tr>
          <td align="left">Image5:</td>
          <td align="left"><label>
            <input type="file" name="userfile[]" />
    		
          </label></td>
        </tr>-->
        <tr>
          <td colspan="2" align="left"><label>
            <input type="submit" name="Submit" value="Submit" />
          </label></td>
        </tr>
      </table>
      
    </form>
    Last edited by Markus; Aug 24 '09, 09:53 AM. Reason: Added [code] tags.
  • dgreenhouse
    Recognized Expert Contributor
    • May 2008
    • 250

    #2
    This may help you get started (you'll have to work out sanitizing the input and validation):
    Code:
    <html>
    <body>
    <?php
     
      if (isset($_POST['submit'])) {
        $uploads = "uploads/";
        print '<pre>';
        print_r($_FILES);
        for ($i=0;$i<count($_FILES['files']['name']);$i++) {
          print $_FILES['files']['name'][$i] . "<br>";
          if (!$_FILES['files']['error'][$i]) {
            move_uploaded_file(
              $_FILES['files']['tmp_name'][$i],
              $uploads . $_FILES['files']['name'][$i]
            );
          }
        }
        print '</pre>';
      }
    
    ?>
    <form method="post" action="" enctype="multipart/form-data">
    <input type="file" name="files[]"><br>
    <input type="file" name="files[]"><br>
    <input type="file" name="files[]"><br>
    <input type="submit" name="submit" value="Upload Files">
    </body>
    </html>

    Comment

    Working...