How to do that :
First we will create a file called install.php , it will create a database called
myimages and a table named imgtables and also create a folder called gallery where we are going to store images.
Create a file name install.php
——————————————————
/*
file name : Install.php
purpose : creating a database name myimages
and table imgtables
Create by : Sanjay Prasad
[email protected]
http://www.openplus.in
*/$db=mysqli_connect(“localhost”,”root”,””);
if($db->connect_errno){
echo “Error <br/>”.$sp->error;
}
$query=”create database if not exists myimages”;
if($db->query($query)){
echo “Created database myimages ..<br/>”;
$sp=mysqli_connect(“localhost”,”root”,””,”myimages”);
if($sp->connect_errno){
echo “Error <br/>”.$sp->error;
}
$tbquery=”create table if not exists imgtables(
id int unsigned auto_increment primary key,
imgurl varchar(255),
date varchar(100)
)engine=’InnoDB'”;
if($sp->query($tbquery)){
echo “Table imgtables created Successfully ..<br/> “;
}else{
echo “Error <br/>”.$sp->error;
}
//creating directory gallery
if(mkdir(“gallery”,0777)){
echo “Folder gallery create successfully”;
}else{
echo “Error Creating Directory”;
}
}
else{
echo “Error <br/>”.$sp->error;
}
?>
Now We have to create a file name gallery.php, which will upload images to folder gallery and saved their name like flower.jpg on table filed imgurl.
gallery.php
<html lang=”en”>
<head>
<title>File Uploading</title>
<meta charset=”utf-8″ />
</head><body>
<?php
$sp=mysqli_connect(“localhost”,”root”,””,”myimages”);
if($sp->connect_errno){
echo “Error <br/>”.$sp->error;
}$path=”gallery/”;
if(isset($_POST[‘upload’]))
{
$path=$path.$_FILES[‘file_upload’][‘name’];
if(move_uploaded_file($_FILES[‘file_upload’][‘tmp_name’],$path))
{
echo ” “.basename($_FILES[‘file_upload’][‘name’]).” has been uploaded<br/>”;
echo ‘<img src=”gallery/’.$_FILES[‘file_upload’][‘name’].'” width=”48″ height=”48″/>’;
$img=$_FILES[‘file_upload’][‘name’];
$query=”insert into imgtables (imgurl,date) values(‘$img’,now())”;
if($sp->query($query)){
echo “<br/>Inserted to DB also”;
}else{
echo “Error <br/>”.$sp->error;
}
}
else
{
echo “There is an error,please retry or ckeck path”;
}
}
?>
<form action=”gallery.php” method=”post” enctype=”multipart/form-data”>
<table width=”384″ border=”1″ align=”center”>
<tr>
<td width=”108″>Select File</td>
<td width=”260″><label>
<input type=”file” name=”file_upload”>
</label></td>
</tr>
<tr>
<td><label>
<input type=”submit” name=”upload” value=”Upload File”>
</label></td>
<td> </td>
</tr>
</table>
</form>
</body></html>
Hey, thanks for this nice Script 🙂
I have one question: I'll rename the uploaded file in one step. So my uploaded file looks at the end like this:
1. I upload the picture: flower.jpg
2. Then the script shall rename it to this: $_SESSION['user_id'].flower.jpg
Can someone help me with this problem?
change
$path=$path.$_FILES['file_upload']['name'];
to
$path=$path. $_SESSION['user_id'].$_FILES['file_upload']['name'];
can i use row id instead of user id
This is nice blog which provides online tutorials and video's of different courses like:PHP,HTML,CSS,SEO Tutorials.
Tutorial In Noida
thank you soo much. it worked like a charm. i was running around google for days and finally found this piece of elegant work!! Thank you
great tutorial…i have only one question,,,and that too a lame one…how can i retrieve these files which are stored in the database.like i am sending a text file to someone,that person can download my text file
we are not strong image,we storing their path, we can retrieve like
note 1 is row id …next
$query=$sp->query("select * from imgtables where id='1') or die($sp->error);
$rows=$query->fetch_assoc();
echo $rows['imgurl'];
Sanjay please, how can I add FamilyName etc to save along with the image?
better download my project Adminplus http://www.openplus.in/open-articles/view-story-project-adminplus.htm
you will learn making admin panel uploading picture and so on
संजय जी
थोड़ी सी जिज्ञासा है ।
1- डेटाबेस में स्टोर्ड पोस्ट्स की लिंक कैसे बनायें । मतलब की किसी पोस्ट के टाइटल को क्लिक करने पर वो पोस्ट खुल जाये ये कैसे किया जायेगा ।
2-Php/mysql में seo (सर्च इंजन ऑप्टिमाइज) लिंक कैसे बनायीं जाये ।
सरल और उचित समाधान बताने का कष्ट करें ।
Anand ji ,
ek table create karte post ,columns hai ID, TITLE, DESCRIPTION …..
ID auto_increment hoga, matlab jab ham ek post create karte hai to ek id generate hoti hai man lijiye 5 , jab dusara create karenge tab 6 hoga …
ek page create karte hai read.php ….
jab hum read.php?id=5 pe jaate hai tab $_GET['id']; se 5 collect karte hai aur query karte hai
select * from post where id='5'
aur hume sari details prapt hoti hai
Live example – http://www.openplus.in/jokes/read.php?id=2108
SEO URL
read.php?id=5 ko hum url rewritte tool ki madad se seo friendly url prapt karte hai
Live example – http://www.openplus.in/open-articles/view-story-samsung-z1-tizen-based-os-review.htm
Thanku sanjay… your article is so helpful
Thank you
thank u so much..
Checkout Great beginning php tutorials Very clear and helpful for beginners.
Nice blog…Very useful information is providing by ur blog. Great beginning php tutorials Very clear and helpful for beginners.
Hi, this blog is really amazing and provide me answers to all my questions .This is really informative and I will for sure refer my friends the same.Website Designing Company | Website Design Company
Nice blog…Very useful information is providing by ur blog. Great beginning php tutorials Very clear and helpful for beginners.
Sir how to make downloadebale to our uploaded file for for user please tell me
how to save image automatically from uploaded directory existing file name without database(flat file)
if wanna show the image,
like normal select from db?
Thanks for the great information in your blog PHP
Thanks for such an interesting article here. I was searching for something like that for quite a long time and at last I have found it here.Web Designing Course in Jalandhar
Great point you make there. good POST.. I like your perspective on this subject. straight bevel gears
Ty U are the best!