How To Create File Image Upload With Gallery Using PHP
Submitted by alpha_luna on Wednesday, April 27, 2016 - 16:30.
Related Code: Upload Multiple Images In PHP
Related Code: File Upload With Progress Bar Using PHP
In this article, we are going to learn on How To Create File Image Upload With Gallery Using PHP. This tutorial creates using PHP/MySQL. You can use this source code to your website or social networking site project to have a photo gallery or you can include this to your User Registration With Photo, etc. Let's start with:
And, that's it... You've been successfully created your File Image Upload With Gallery.
This is the Output:
Related Code: Upload Multiple Images In PHP
Related Code: File Upload With Progress Bar Using PHP
Just download the complete source code below. By clicking the "Download Code" button.
Share us your thoughts and comments below. Thank you so much for dropping by and reading this tutorial post. For more updates, don’t hesitate and feel free to visit this website more often and please share this with your friends or email me at [email protected]. Practice Coding. Thank you very much.
Creating our Table
For the first step, we are going to make our database. To create a database:- Open PHPMyAdmin
- Create a database and name it as "biobook".
- After creating a database name, click the SQL and kindly copy the code below.
- --
- -- Table structure for table `photos`
- --
Form Field
This form where the user can choose their photo to upload then it will show in the gallery.- <div id="right-nav">
- <h1>Your Photos</h1>
- <div>
- <form method="post" action="add_photo.php" enctype="multipart/form-data">
- <input type="file" name="image">
- <button class="btn-submit-photo" name="Submit" value="Log out">Add Photos</button>
- </form>
- <hr />
- </div>
- <?php
- include("includes/database.php");
- $id = $row['photo_id'];
- ?>
- <div class="photo-select">
- <center>
- <img src="<?php echo $row['location']; ?>">
- <hr>
- <a href="delete_photos.php<?php echo '?id='.$id; ?>" class="btn-delete-photos">Delete</a>
- </center>
- </div>
- <?php
- }
- ?>
- </div>
Creating Connection
This PHP source code is our database connection, kindly copy and save it as "database.php".- <?php
- ?>
File Upload PHP Script
This source code will execute to save the photos to database and save it as "add_photo.php".- <?php
- include('includes/database.php');
- include('session.php');
- echo "";
- }else{
- $file=$_FILES['image']['tmp_name'];
- $image = $_FILES["image"] ["name"];
- $size = $_FILES["image"] ["size"];
- $error = $_FILES["image"] ["error"];
- if ($error > 0){
- }else{
- if($size > 10000000) //conditions for the file
- {
- }
- else
- {
- $location="upload/" . $_FILES["image"]["name"];
- $user=$_SESSION['id'];
- }
- }
- }
- ?>
Add new comment
- 1350 views