Bagaimana cara mengupload gambar di MySQL menggunakan PHP PDO?



include "database_connection.php";


if(isset($_POST['submit'])) {



    $countfiles = count($_FILES['files']['name']);



    $query = "INSERT INTO images (name,image) VALUES(?,?)";


    $statement = $conn->prepare($query);



    for($i = 0; $i < $countfiles; $i++) {



        $filename = $_FILES['files']['name'][$i];



        $target_file = 'upload/'.$filename;



        $file_extension = pathinfo(

            $target_file, PATHINFO_EXTENSION);


        $file_extension = strtolower($file_extension);



        $valid_extension = array("png","jpeg","jpg");


        if(in_array($file_extension, $valid_extension)) {






            ) {









    echo "File upload successfully";




<!DOCTYPE html>

<html lang="en">



    <meta charset="UTF-8">

    <meta name="viewport" content=

        "width=device-width, initial-scale=1.0">

    <title>Geeks for geeks Image Upload</title>




    <h1>Upload Images</h1>


    <form method='post' action=''


        <input type='file' name='files[]' multiple />

        <input type='submit' value='Submit' name='submit' />



    <a href="view.php">|View Uploads|</a>




How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.