
Upload image to mysql by php
Welcome my reader ! A long time I avoid from blogging for my study .But I don’t forget my reader .I always stay on my gmail and facebook (Look below my post) . Have you any problem about web development or other? please knock to my mail , I will try to feedback as soon as possible . however , Today we learn about image upload with php ! .So go to main subject
Step 1
We create a php page named Upload.php . And create a form in html body same as below
Step 2After written html code create php code for image upload . firstly create code for connection to the mysql and database . look below
Save it dbc.php
As your wish select database name . we create database name up. Create a table named tbl_up and create two row id , image [datatype BLOB].
CREATE TABLE `tbl_up` ( `id` INT NOT NULL AUTO_INCREMENT , `image` BLOB NOT NULL , PRIMARY KEY ( `id` ) );
Now we create main php image upload script .please wait and read take a long time .
if (isset($_POST[' imsubmit '])) { include('dbc.php'); $image = addslashes(file_get_contents($_FILES['image']['tmp_name'])); $sql=mysql_query("INSERT into members (image) values ('$image')",$con); if($sql) { echo "Image uploaded successfully"; } } else{ echo "please upload image"; } ?>
Isset if press submit then work in{work area} double brakate , include the dbc.php for mysql and database connection . Now take a $image variable addslashes for add slash and file_get_content for image file information . $sql = mysql_query is work for insert image to mysql . after that simple If Else condition .
All code of up.php
Test it for upload image to mysql with BLOB datatype . have you any problem please comment I will try to solve .
Please wait for my next tutorial – show image from mysql
Oh yeah, nice job dude. Can you tell me, how can I show images from my mysql DB
hey @mit,=D
oh, yah i post this topic as soon as possible