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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jagadishk
    New Member
    • Jan 2014
    • 1

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

    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.

    Code:
    <?php
    include 'config.php';
    error_reporting(E_ALL ^ E_NOTICE);
    if(isset($_POST['submit']))
    {
    $target = "http://bytes.com/images/";
    $target = $target . basename( $_FILES['photo']['name']); 
    $name = $_POST['name'];
    $pic = ($_FILES['photo']['name']);
    $sql = mysql_query("INSERT INTO `myimages` (`name`, `picture`) VALUES ('$name', '$pic');"); 
    
    if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
    {
    echo '<center>Image uploaded Saved Success</center>';
    }
    else
    {
    echo '<center>Not Saved</center>';
    }
    }
    ?>
    Last edited by Rabbit; Jan 4 '14, 04:27 AM. Reason: Please use [CODE] and [/CODE] tags when posting code or formatted data.
  • Luuk
    Recognized Expert Top Contributor
    • Mar 2012
    • 1043

    #2
    When using a form like:
    Code:
    <form action=upload.php enctype="multipart/form-data" method=post>
    <input type=file name="file[]"><br>
    <input type=file name="file[]"><br>
    <input type=submit name=submit><br>
    </form>
    You should find an array like this in PHP
    Code:
    Array ( [file] => 
     Array ( 
      [name] => 
        Array ( [0] => filename1.jpg [1] => filename2.jpg )
      [type] => 
        Array ( [0] => image/jpeg [1] => image/jpeg )
      [tmp_name] => 
        Array ( [0] => /tmp/phpx3AyMX [1] => /tmp/phpgQjjyl )
      [error] => 
        Array ( [0] => 0 [1] => 0 )
      [size] => 
        Array ( [0] => 25016 [1] => 90566 ) ) )
    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];

    Comment

    Working...