By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,002 Members | 2,137 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,002 IT Pros & Developers. It's quick & easy.

hi this is my code for uploading images into data base which is woring fine, but i wa

P: 1
hi this is my code for uploading images into data base which is woring fine, but i want to upload multiple images an any one help me.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include 'config.php';
  3. error_reporting(E_ALL ^ E_NOTICE);
  4. if(isset($_POST['submit']))
  5. {
  6. $target = "http://bytes.com/images/";
  7. $target = $target . basename( $_FILES['photo']['name']); 
  8. $name = $_POST['name'];
  9. $pic = ($_FILES['photo']['name']);
  10. $sql = mysql_query("INSERT INTO `myimages` (`name`, `picture`) VALUES ('$name', '$pic');"); 
  11.  
  12. if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
  13. {
  14. echo '<center>Image uploaded Saved Success</center>';
  15. }
  16. else
  17. {
  18. echo '<center>Not Saved</center>';
  19. }
  20. }
  21. ?>
Jan 4 '14 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 1,035
When using a form like:
Expand|Select|Wrap|Line Numbers
  1. <form action=upload.php enctype="multipart/form-data" method=post>
  2. <input type=file name="file[]"><br>
  3. <input type=file name="file[]"><br>
  4. <input type=submit name=submit><br>
  5. </form>
You should find an array like this in PHP
Expand|Select|Wrap|Line Numbers
  1. Array ( [file] => 
  2.  Array ( 
  3.   [name] => 
  4.     Array ( [0] => filename1.jpg [1] => filename2.jpg )
  5.   [type] => 
  6.     Array ( [0] => image/jpeg [1] => image/jpeg )
  7.   [tmp_name] => 
  8.     Array ( [0] => /tmp/phpx3AyMX [1] => /tmp/phpgQjjyl )
  9.   [error] => 
  10.     Array ( [0] => 0 [1] => 0 )
  11.   [size] => 
  12.     Array ( [0] => 25016 [1] => 90566 ) ) ) 
  13.  
above is the 'formatted' output of print_r($_FILES)

now you refer to (line#5):
$pic = ($_FILES['photo']['name']);

with above example you can use:
$_FILES['file']['name'][0];
and
$_FILES['file']['name'][1];
Jan 4 '14 #2

Post your reply

Sign in to post your reply or Sign up for a free account.