I have stored a image name in database this way, and I am not sure if the image name is inserted in it or not. However, I can see something of 14 B in blob type of image column.
$newImageSubmitted = isset( $_FILES['image'] );
if ( $newImageSubmitted )
{
include_once "uploader.class.php";
$uploader = new Uploader( "image" );
$uploader->saveIn("img");
$fileUploaded = $uploader->save();
}
$db = new mysqli("localhost", "root","","learndb");
if ($db->connect_error) {
die("Connection failed this is the error: " . $db->connect_error);
}
if($fileUploaded)
{
$stmt = $db->prepare("INSERT INTO studentrecords (Name, email, Phone, school,dob,father,feereceived,due,image) VALUES (?,?,?,?,?,?,?,?,?)");
if($stmt)
{
$stmt->bind_param("ssisssiis",$name,$email,$phone,$school,$dob,$father,$feereceived,$due,$fileUploaded);
$stmt->execute();
include_once"viewstudentrecords1.php";
$out="<center>information entered.</center>";
echo "$out";
}
but displaying image this way is not working for me:
echo '<img src="data:image/jpeg;base64,'.base64_encode( $myrow['image'] ).'"/ width="200" height="200">';
uploader.class.php
<?php
class Uploader {
private $filename;
private $fileData;
private $destination;
public function __construct( $key ) {
$this->filename = $_FILES[$key]['name'];
$this->fileData = $_FILES[$key]['tmp_name'];
}
public function saveIn( $folder ) {
$this->destination = $folder;
}
public function save(){
$folderIsWriteAble = is_writable( $this->destination );
if( $folderIsWriteAble ){
$name = "$this->destination/$this->filename";
if($succes = move_uploaded_file( $this->fileData, $name ))
{
return $name;
}
} else {
trigger_error("cannot write to $this->destination");
$succes = false;
}
return $succes;
}
}