HOW TO STORE IMAGES IN DATABASES
<?php
mysql_connect("localhost","root","");
mysql_select_db("test");
$cont = file_get_contents("winter.jpg");
$cont = addslashes($cont);
if(mysql_query("insert into tbl_images values('','$cont')"))
echo "IMage is added";
else
echo "not";
?>
TABLE
sno int auto_increment primary key, image BLOB or LONG BLOB
RETRIEVE IMAGES FROM DATABASE
<?php
header("Content-type:image/jpeg");
mysql_connect("localhost","root","");
mysql_select_db("test");
$data = mysql_query("select * from tbl_images where imgid=3");
$rec = mysql_fetch_row($data);
echo $rec[1];
?>
Store images in database
INSERT statement SQL
insert into tbl_user (uname) values ('John');
insert into tbl_user values ('alex','alex123'),('rajesh','rajesh123');
Sessions Login Logout
<?php
if(isset($_POST['sub'])){
$uname = $_POST['txtuname'];
$pwd = $_POST['txtpwd'];
if($uname=="scott" and $pwd=="scott123"){
session_start();
$_SESSION['aut'] = true;
echo "<script>location='welcome.php';</script>";
}
else{
echo "invalid";
}
}
?>
<form method="post" action="">
Username:<input type="text" name="txtuname">
Password:<input type="password" name="txtpwd">
<input type="submit" name="sub" value="login">
</form>
WELCOME.PHP
<?php
session_start();
if(isset($_SESSION['aut'])){
echo "Welcome to user";
}
else{
echo "<script>location='login.php';</script>";
}
?>
<a href="logout.php">Logout</a><link rel="canonical" href="">
LOGOUT.PHP
<?php
session_start();
session_destroy();
echo "Logout successful";
?>
File Upload in php
<form method="post" action="" enctype="multipart/form-data">
Select File: <input type="file" name="f1">
<input type="submit" name="sub" value="Upload">
</form>
<?php
if(is_uploaded_file($_FILES['f1']['tmp_name'])){
$fname = $_FILES['f1']['name'];
if(move_uploaded_file($_FILES['f1']['tmp_name'], "../testing/$fname"))
echo "File moved";
else
echo "File not moved";
}
else
echo "File not uploaded";
?>