因此,我正在尝试编写代理模式代码,该代码应加载并显示数据库中的图像。我想知道是否有可能,有人可以帮我解决我的问题。
interface File
{
public function display(): void;
}
class RealFile implements File
{
private $usrid, $content;
public function __construct(int $usrid)
{
$this->usrid = $usrid;
$this->load($usrid);
}
public function load( int $userid): void
{
$sql = "SELECT profile_img FROM users WHERE id=:userid";
$imagee= DB::query($sql, array(':userid'=>$userid));
$imagee= (file_get_contents($_FILES['image']['tmp_name']));
$this->content = $imagee;
}
public function display(): void
{
$typeSQL = "SELECT mime FROM users WHERE id=:userid";
$type= DB::query($typeSQL, array(':userid'=>$this->usrid));
echo '<img height="300" width="300" src="data:'.$type.';base64,'. base64_encode($this->content).'"> ';
}
}
class ProxyFile implements File
{
private $realFile, $usrid;
public function __construct($usrid)
{
$this->usrid = $usrid;
}
public function display(): void
{
if ($this->realFile == null){
$this->realFile = new RealFile($this->usrid);
}
echo $this->realFile->display();
}
}
我得到的错误是:
注意:未定义索引:第61行的C:\ xampp \ htdocs \ Unbox \ photoTEST.php中的图片
警告:file_get_contents():在第61行的C:\ xampp \ htdocs \ Unbox \ photoTEST.php中文件名不能为空
注意:第70行的C:\ xampp \ htdocs \ Unbox \ photoTEST.php中的数组到字符串的转换