CREATE TABLE t_image (f_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, f_image BLOB );
//put image to mysql
//http://192.168.0.10/picphp/1.php?pic=4.jpeg
<?php
include("../catlib.php");
?>
<?PHP
$user1='bunny';
$password1='12341234';
$database1='d_vegetable';
$Picture=$_GET['pic'];
if($Picture == ""){
die("no _GET pic");
}
html_head();
header1();
no_cache();
head_body();
If($Picture != "none") {
$PSize = filesize($Picture);
echo "size $PSize";br();
$file_content=base64_encode(fread(fopen($Picture, "rb"), $PSize));
$conn=mysqli_connect('localhost',$user1,$password1,$database1);
if ($conn) {
echo"ok1";br();
$st1="INSERT INTO t_image VALUES(NULL,'$file_content')";
if (mysqli_query($conn,$st1)){
echo"ok2";br();
} else {
die("Can't Perform Query");
}
} else {
echo "-1";
}
} else {
echo"You did not upload any picture";
}
body_html_s();
?>
//get image form mysql
//http://192.168.0.10/picphp/2.php?pic_id=4
<?php
include("../catlib.php");
?>
<?PHP
$user1='bunny';
$password1='12341234';
$database1='d_vegetable';
$pic_id=$_GET['pic_id'];
if($pic_id == ""){
die("no _GET pic_id");
}
$conn=mysqli_connect('localhost',$user1,$password1,$database1);
if ($conn) {
$st1="select f_image from t_image where f_id='$pic_id'";
if ($picdata=mysqli_query($conn,$st1)){
header("Content-Type:image/jpeg");
echo base64_decode(mysqli_fetch_row($picdata)[0]);
} else {
die("Can't Perform Query");
}
} else {
echo "-1";
}
?>