Home » Jquery » javascript – Upload multiple images in database issue-Exceptionshub

javascript – Upload multiple images in database issue-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment

Questions:

I want to upload multiple images using single input. The problem is only one images can be add in database. Can someone assist me how to implement loop in this codes?

html

 <input id="fileupload" type="file" name="files[]" multiple style="width:25%" />

php

if ($_FILES['climage']['size'] != 0){
        $imgUnique = randomString(5);
        var_dump($_FILES);
        die();
        $att_image = $imgUnique.basename($_FILES["climage"]["name"]);
        $att_image = str_replace(' ', '_', $att_image);
        $att_dir = "dist/img/user/";
        $att_file = $att_dir . $att_image;

        if (move_uploaded_file($_FILES["climage"]["tmp_name"], $att_file)) 
        {
            $sql_updTemp = "UPDATE tbltempclaim SET $_clmImg='".$att_image."' WHERE $_claimTempId='".$_SESSION['claimId']."'";
            var_dump($sql_updTemp);
            die();
            if($result_updTemp = $conn->query($sql_updTemp))
            {
                unset($_SESSION['claimId']);
                //echo "1";
            }
            else
            {
                echo "<script language='javascript'>alert('Fail to update image name');</script>";
            }
        }
        else 
        {
            echo "<script language='javascript'>alert('Fail upload image');</script>";
        }
    }
How to&Answer: