S24 Upload Image and View

S24 Upload Image and View

Image Upload Form

<!DOCTYPE html>

<html>
<head>  <title>Image Upload in PHP</title>
</head>
<body>
    <div>
        <! specify the encoding type of the form using the enctype attribute >
        <form method=”POST” action=”imageupload.php” 
        enctype=”multipart/form-data”>
            <input type=”file” name=”iii” value=”” />
            <input type=”text” name=”username”/>
    <div>
<button type=”submit” name=”uploadfile”>UPLOAD</button>
</div>
        </form>

    </div>

</body>

</html>


Image Upload PHP

<?phperror_reporting(0);?>

<?php
$msg = “”; 
// check if the user has clicked the button “UPLOAD” 

if (isset($_POST[‘uploadfile’])) {

    $imagename = $_FILES[“iii”][“name”];

    $tempname = $_FILES[“iii”][“tmp_name”];  

        $folder = “image/”.$imagename;   
    
    // connect with the database

$db = mysqli_connect(“localhost”, “user”, “password”, “databasename”); 

        // query to insert the submitted data

 $sql = “INSERT INTO regform (imagename) VALUES (‘$imagename’)”;

        // function to execute above query

        mysqli_query($db,$sql);      
}
        // Add the image to the “image” folder”

        move_uploaded_file($tempname, $folder)

?>


View Image File

<!DOCTYPE html>
<html>
<body>

<?php
include(“config.php”);
$sql = “SELECT * FROM regform Where username=’writeusername'”;
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo “<br> username: “. $row[“username”].
            “<br> Image Name: “.$row[“imagename”].
            “<br><img src=’image/”.$row[“imagename”].”‘/>” ;
    }
} else {
    echo “0 results”;
}

$conn->close();
?>
</body>
</html>

Take Your Free Live Demo Class Now

We Will Call Back You Shortly

Enter Your DETAILS BELOW

We Will Send You the Course Fees Details In Below Number

Enter Your DETAILS BELOW

We Will Call Back You Shortly

Enter Your DETAILS BELOW

We Will Call Back You Shortly

Enter Your DETAILS BELOW

Enter Your DETAILS BELOW TO take

free demo class