You are on page 1of 2

7/14/2014 Web Developer,blogger and thinker: upload images into MySQL database using PHP code

http://websitedesign9.blogspot.in/2013/10/upload-images-into-mysql-database-using.html 1/2
Core PHP programmer and website designer. also works on E-commerce Website Using Magento.
Web Developer,blogger and thinker
Home CSS E-Book
Friday, October 25, 2013
upload images into MySQL database using PHP code
Image uploading is very useful features and has been use by everybody while creating attractive websites. There are many
ways to upload images using form.
The very attractive code for image uploading by checking image extension, file size. Below will also provide solution for
multiple image uploading features.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Comment
<!--?php
include('conn.php');
if(isset($_POST['Submit']))
{
$path = "uploads/";
function getExtension($str)
{
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
} $valid_formats = array("jpg", "png", "gif", "bmp","jpeg","PNG","JPG","JPEG","GIF","BMP"
if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST")
{
$name = $_FILES['photog']['name'];
$size = $_FILES['photog']['size'];
if(strlen($name))
{
$ext = getExtension($name);
if(in_array($ext,$valid_formats))
{
if($size
<(1024*1024))
{
$actual_image_name = time().substr(str_replace(" ", "_", $txt), 5).".".$ext;
$tmp = $_FILES['photog']['tmp_name'];
if(move_uploaded_file($tmp, $path.$actual_image_name))
{
mysql_query("UPDATE profile SET profile_image='$actual_image_name' WHERE uid='$session_id'"

echo "
<img src='uploads/".$actual_image_name."' class='preview'-->
";
}
else
echo "Fail upload folder with read access.";
}
else
}
echo "Image file size max 1 MB";
}
else
echo "Invalid file format..";
}
else
echo "Please select image..!";
exit;
}
}
?>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Comment




<script type="text/javascript" src="scripts/jquery.min.js"></script>
<script type="text/javascript" src="scripts/jquery.wallform.js"></script>
<script type="text/javascript">
$(document).ready(function() {

$('#photog').die('click').live('change', function() {
//$("#preview").html('');

$("#gform").ajaxForm({target: '#preview',
beforeSubmit:function(){
console.log('v');
$("#imgloadstatus").show();
$("#imageloadbutton").hide();
},
success:function(){
console.log('z');
$("#imgloadstatus").hide();
$("#imageloadbutton").show();
},
error:function(){
console.log('d');
Name
Email *
Message *
Send
Contact Form
Pintoo Gautam
I am the web developer.
work on various web
technology like object
oriented core PHP ,
MYSQL. also work on responsive
website design.
View my complete profile
About Me
June (1)
April (2)
February (1)
January (2)
October (7)
May (1)
Blog Archive
Join this site
with Google Friend Connect
Members (5)
Already a member? Sign in
Followers
0

More

Next Blog Create Blog

Sign In
?
?
7/14/2014 Web Developer,blogger and thinker: upload images into MySQL database using PHP code
http://websitedesign9.blogspot.in/2013/10/upload-images-into-mysql-database-using.html 2/2
Newer Post Older Post Home
Subscribe to: Post Comments (Atom)
Posted by Pintoo Gautam at 10:11 PM
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
$("#imgloadstatus").hide();
$("#imageloadbutton").show();
} }).submit();
});
});
</script>

<style>
body
{
font-family:arial;
}
.preview
{
width:200px;
border:solid 1px #dedede;
padding:10px;
}
#preview
{
color:#cc0000;
font-size:12px
}
</style>

<div style="width:600px">
<div id="preview">
</div>
<form id="gform" method="post" enctype="multipart/form-data" action="">
Upload your image
<div id="imgloadstatus" style="display:none"><img src="loader.gif" alt="Uploading...."></div>
<div id="imageloadbutton">
<input type="file" name="photog" id="photog">
</div>
</form>
</div>
Recommend this on Google
Enter your comment...
Comment as:
Google Account
Publish

Preview
1 comment:
pvahora November 5, 2013 at 3:38 AM
The article is good to read and worth sharing
Hire Magento Developers
Reply
Awesome Inc. template. Powered by Blogger.

You might also like