PHP image upload,Store into MySQL DB,Show all images Script Download

How to create php code that’s upload image on folder,Save image name+path into database and display all uploaded images.

In this tutorial we are sharing with you our recently designed image uploading script in PHP scripting language. This Script will gives us the facility to upload online images on our web hosting server and save that images into MySQL database in PhpMyAdmin so it can be easily assessable again via PHP. So in here you can upload images and display all the uploaded images using Click Here To Show All Uploaded Images link under the upload box. So here is the complete step by step tutorial for PHP image upload,Store into MySQL DB,Show all images Script Download.

android-project-download-code-button

PHP image upload,Store into MySQL DB,Show all images Script Download.

List of Files in this script :

  1. index.php
  2. dbconfig.php
  3. show-images.php
  4. style.css

Code for index.php file.

 <!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>PHP image upload,Store into MySQL DB,Show all images Script Download</title>
<link href="style/style.css" rel="stylesheet" type="text/css">
</head>
<body>

<form action="" method="post" enctype="multipart/form-data">
<table border="2" cellpadding="15" cellspacing="2" width="430" align="center">
<tr class="tabheader">
<td align="center" colspan="2">Image Upload & Save into MySQL db</td>
</tr>
<tr class="row">
<td>Select File Here:</td>
<td><input type="file" name="uploadImage" id="uploadImage"></td>
</tr>
<tr class="tabheader">
<td colspan=2><p align=center>
<input type="submit" value="Click Here To Upload" name="submit">
</td>
</tr>

<tr class="tabheader">
<td colspan=2><p align=center>
<a href="show-images.php">Click Here To Show All Uploaded Images </a>
</td>
</tr>

</table>
</form>

<?php

//Adding isset button function on submit button.
if(isset($_POST["submit"])) {
 
 if (!empty($_FILES["uploadImage"]["name"])) {

include '../dbconfig.php';

$ImageSavefolder = "uploads/";

move_uploaded_file($_FILES["uploadImage"]["tmp_name"] , "$ImageSavefolder".$_FILES["uploadImage"]["name"]);

mysql_query("INSERT into image_upload (image_name) VALUES('".$_FILES['uploadImage']['name']."')");

if($conn) { 

echo '<p align="center"> Image name successfully saved into MySQL db.</p>'; 

}

else {
 
echo '<p align="center"> Sorry, Please try again.</p>';
}
 }
 else {
 
 echo '<p align="center"> Select file to upload </p>';
 
 }

 }
 
?>


</body>
</html>

Code for show-images.php file.

 <!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Display All Images</title>
<link href="Style/style.css" rel="stylesheet" type="text/css">
</head>

<body>

<?php

include 'dbconfig.php';

$image_query = mysql_query("SELECT * FROM image_upload") or die(mysql_error());

$file_path = 'http://localhost/home/image-script/uploads/';
echo '<div class="images_show">';
echo '<center><h1> All Uploaded Images Display Here </h1></center>';
echo '</div>';
while($all_images = mysql_fetch_assoc( $image_query ))

{
 
$img_src = $file_path.$all_images['image_name'];

echo '<div class="images_show">';
echo "<center><img src=".$img_src." > </center> </br>";
echo '</div>';
}
?>

</body>
</html>

Code for style.css file.

  @charset "utf-8";
/* CSS Document */

.tabheader {
background-color:#db02fb;
color:white;
font-weight:bold;
}
.row {
background-color: #fb02bd;
color:white;
}

.tabheader a {
 
 color:#F9F7F7;
 text-decoration:none;
 
 }
 
 .images_show {
background-color: #EF9A9A;
color:white;
}
 
.images_show img {
 
 border: 2px solid #1FFF32;
 
 }

Code for dbconfig.php file.

 <?php

//Define your host here.
$hostname = "localhost";

//Define your database username here.
$username = "root";

//Define your database password here.
$password = "";

//Define your database name here.
$dbname = "test";

 $conn = mysql_connect($hostname, $username, $password);
 
 if (!$conn)
 
 {
 
 die('Could not connect: ' . mysql_error());
 
 }
 
 mysql_select_db($dbname, $conn);



?>

Screenshots:

PHP image upload,Store into MySQL DB,Show all images Script Download

show-images

Click here to download PHP image upload,Store into MySQL DB,Show all images Script Download project with source code.

Leave a Reply

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