HOME / BLOG / BLOG-POST

How to upload an image to database using php

<?php
error_reporting(0); //for no error reporting
?>

<html>
    <head>
        <title>img insert</title>
    </head>
    <body>
        <?php
        $filename = $_FILES["image"] ["name"];
        $tempname = $_FILES["image"] ["tmp_name"];
        $folder = "img/" . $filename; //giving your folder directory
        move_uploaded_file($tempname,$folder); //for moving uploaded file to ur own folder
        ?>
        <form action="" method="post" enctype="multipart/form-data">
            <input type="file" name="image" />
            <input type="submit" name="submit" />
        </form>
        <?php if(isset($_POST["submit"])) { ?>
        <img src="<?php echo $folder ?>" height="auto" width="auto"> <?php } ?> //showing image
    </body> 

</html>

about authors

Sandip Das

Web Developer

Once a legend said “Any fool can write code that a computer can understand. Good programmers write code that humans can understand.” – Martin Fowler.



POST COMMENTS

Leave a Reply

Your email address will not be published. Required fields are marked *