Connecting Tech Pros Worldwide Help | Site Map

multiple images uploader

Newbie
 
Join Date: Aug 2009
Posts: 5
#1: Aug 24 '09
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)
Expand|Select|Wrap|Line Numbers
  1. <?
  2.   include_once('connection_db.php');
  3.   $username=$_REQUEST['name'];
  4.   $index=$_REQUEST['cboxcata'];
  5.   if($_REQUEST){
  6.   for($i=1;$i<3;$i++){
  7.   $filename= $_FILES["userfile"]["name"][$i];
  8.                move_uploaded_file($_FILES["userfile"]["tmp_name"][$i], "../upload/".$filename);
  9.  
  10.  
  11.    }
  12.       $q="insert into person(image)values('$filename')";
  13.  
  14.       $r=mysql_query($q);
  15.      header("location:test.php");
  16.  
  17. }
  18.  
  19.  
  20. ?>
  21. htlm file is:
  22. <form name="" action="test1.php" method="post" enctype="multipart/form-data">
  23.  
  24.   <table width="350" border="0" align="center">
  25.     <tr>
  26.       <td colspan="2" align="center"><?=$msg?></td>
  27.     </tr>
  28.  
  29.     <tr>
  30.       <td align="left">Image1:</td>
  31.       <td align="left"><input type="file" name="userfile[1]" /></td>
  32.     </tr>
  33.     <tr>
  34.       <td align="left">Image2:</td>
  35.       <td align="left"><input type="file" name="userfile[2]" /></td>
  36.     </tr>
  37.     <!--<tr>
  38.       <td align="left">Image3:</td>
  39.       <td align="left"><input type="file" name="userfile[]" /></td>
  40.     </tr>
  41.     <tr>
  42.       <td align="left">Image4:</td>
  43.       <td align="left"><input type="file" name="userfile[]" /></td>
  44.     </tr>
  45.     <tr>
  46.       <td align="left">Image5:</td>
  47.       <td align="left"><label>
  48.         <input type="file" name="userfile[]" />
  49.  
  50.       </label></td>
  51.     </tr>-->
  52.     <tr>
  53.       <td colspan="2" align="left"><label>
  54.         <input type="submit" name="Submit" value="Submit" />
  55.       </label></td>
  56.     </tr>
  57.   </table>
  58.  
  59. </form>
dgreenhouse's Avatar
Newbie
 
Join Date: May 2008
Location: San Francisco
Posts: 3
#2: Aug 26 '09

re: multiple images uploader


This may help you get started (you'll have to work out sanitizing the input and validation):
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3. <?php
  4.  
  5.   if (isset($_POST['submit'])) {
  6.     $uploads = "uploads/";
  7.     print '<pre>';
  8.     print_r($_FILES);
  9.     for ($i=0;$i<count($_FILES['files']['name']);$i++) {
  10.       print $_FILES['files']['name'][$i] . "<br>";
  11.       if (!$_FILES['files']['error'][$i]) {
  12.         move_uploaded_file(
  13.           $_FILES['files']['tmp_name'][$i],
  14.           $uploads . $_FILES['files']['name'][$i]
  15.         );
  16.       }
  17.     }
  18.     print '</pre>';
  19.   }
  20.  
  21. ?>
  22. <form method="post" action="" enctype="multipart/form-data">
  23. <input type="file" name="files[]"><br>
  24. <input type="file" name="files[]"><br>
  25. <input type="file" name="files[]"><br>
  26. <input type="submit" name="submit" value="Upload Files">
  27. </body>
  28. </html>
  29.  
Reply


Similar PHP bytes