我已经以这种方式将图像名称存储在数据库中,我不确定图像名称是否插入其中。但是,我可以在blob类型的图像列中看到14 B的东西。
$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";
}
但以这种方式显示图片对我不起作用:
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;
}
}
答案 0 :(得分:0)
对于这一行:
echo '<img src="data:image/jpeg;base64,'.base64_encode( $myrow['image'] ).'"/ width="200" height="200">';
应该{{1}}而不是/"
来转义引号。