How To Build Profile Picture Upload In PHP, Just Like Facebook
By Mark Chidozie
2 years ago
556
Programming
<?php
//Create database connection
$db = mysqli_connect("localhost", "root", "", "image_upload");
//Initialize message variable
$msg = "";
// If upload button is clicked ...
if (isset($_POST['upload'])) {
// Get image name
$image = $_FILES['image']['name'];
// Image file directory
$target = "images/".basename($image);
$sql = "INSERT INTO images (image) VALUES ('$image')";
// Execute query
mysqli_query($db, $sql);
if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) {
$msg = "Image uploaded successfully";
}
else{
$msg = "Failed to upload image";
}
}
$result = mysqli_query($db, "SELECT * FROM images");
?>
<!DOCTYPE html>
<html>
<head>
<style>
.dropbtn {
background-color: #4CAF50;
color: white;
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
right: 0;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}
.dropdown-conte
background-color: #3e8
</style>
<title>COLLECT PHOTO</title>
<link rel="stylesheet" href="style.css">
</head>
<body style="background-color: #673AB7">
<center>
<div class="dropdown" style="float: left;">
<button class="dropbtn">Profile</button>
<div class="dropdown-content" style="left: 0;">
<a href="index1.php">SELECT</a>
<a href="#">STORE</a>
</div>
</div>
<div class="me">
<hr>
<h1 class="glow" style="font-family: cursive; font-size: 50px">Your Website's Name Goes Here</h1>
<hr>
<?php
while ($row = mysqli_fetch_array($result)) {
echo "<div id='image_div'>";
echo "<img src='images/".$row['image']."'>";
echo "</div>";
}
?>
<form method="POST" action="collectphoto.php" enctype="multipart/form-data">
<video width="320" height="240" controls>
<source src="video/vidpam.mp4" type="video/mp4">
</video>
<h3 style="color: red">BELIEVE IN YOURSELF</h3>
<h2.1>WELCOME<span style="color: white"> TO OUR</span> WORLD</h2.1>
<hr>
</center>
</div>
</body>
</html>
Login to comment and earn
2 years ago
Thank God for this thanks
1 year ago
You sure about what you're saying
1 year ago
Colder and colder
1 year ago
Oh my God
1 year ago
Yes we thank God for this ooo
1 year ago
I love this one too