dsstlsqt696435 2016-02-17 11:23
浏览 48

显示使用图像名称存储的图像

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;
}
}
  • 写回答

1条回答 默认 最新

  • doutan1671 2016-02-17 11:30
    关注

    For this line:

    echo '<img src="data:image/jpeg;base64,'.base64_encode( $myrow['image'] ).'"/ width="200" height="200">';
    

    It should be /" instead of "/ to escape quotes.

    评论

报告相同问题?

悬赏问题

  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计