PHP和mySQL从数据库上传pdf格式的图像
我试图以pdf格式显示MySQL表中的图像。I当我执行代码时,我收到以下错误:PHP和mySQL从数据库上传pdf格式的图像,php,mysql,pdf,Php,Mysql,Pdf,我试图以pdf格式显示MySQL表中的图像。I当我执行代码时,我收到以下错误: 连接建立数据库选择查询:从id=31的用户处选择*执行FPDF错误:不支持的图像类型:/Û7úwè(ê-Òº您必须使用MemImage功能来显示图像的blob数据 $pdf->MemImage($url, 50, 30); 编辑 来源 <?php require('fpdf.php'); //Stream handler to read from global variables class Var
连接建立数据库选择查询:从id=31的用户处选择*执行FPDF错误:不支持的图像类型:/Û7úwè(ê-Òº您必须使用
MemImage
功能来显示图像的blob
数据
$pdf->MemImage($url, 50, 30);
编辑
来源
<?php
require('fpdf.php');
//Stream handler to read from global variables
class VariableStream
{
var $varname;
var $position;
function stream_open($path, $mode, $options, &$opened_path)
{
$url = parse_url($path);
$this->varname = $url['host'];
if(!isset($GLOBALS[$this->varname]))
{
trigger_error('Global variable '.$this->varname.' does not exist', E_USER_WARNING);
return false;
}
$this->position = 0;
return true;
}
function stream_read($count)
{
$ret = substr($GLOBALS[$this->varname], $this->position, $count);
$this->position += strlen($ret);
return $ret;
}
function stream_eof()
{
return $this->position >= strlen($GLOBALS[$this->varname]);
}
function stream_tell()
{
return $this->position;
}
function stream_seek($offset, $whence)
{
if($whence==SEEK_SET)
{
$this->position = $offset;
return true;
}
return false;
}
function stream_stat()
{
return array();
}
}
class PDF_MemImage extends FPDF
{
function PDF_MemImage($orientation='P', $unit='mm', $format='A4')
{
$this->FPDF($orientation, $unit, $format);
//Register var stream protocol
stream_wrapper_register('var', 'VariableStream');
}
function MemImage($data, $x=null, $y=null, $w=0, $h=0, $link='')
{
//Display the image contained in $data
$v = 'img'.md5($data);
$GLOBALS[$v] = $data;
$a = getimagesize('var://'.$v);
if(!$a)
$this->Error('Invalid image data');
$type = substr(strstr($a['mime'],'/'),1);
$this->Image('var://'.$v, $x, $y, $w, $h, $type, $link);
unset($GLOBALS[$v]);
}
function GDImage($im, $x=null, $y=null, $w=0, $h=0, $link='')
{
//Display the GD image associated to $im
ob_start();
imagepng($im);
$data = ob_get_clean();
$this->MemImage($data, $x, $y, $w, $h, $link);
}
}
?>
范例
<?php
require('mem_image.php');
$pdf = new PDF_MemImage();
$pdf->AddPage();
//Load an image into a variable
$logo = file_get_contents('logo.jpg');
//Output it
$pdf->MemImage($logo, 50, 30);
//Create a GD graphics
$im = imagecreate(200, 150);
$bgcolor = imagecolorallocate($im, 255, 255, 255);
$bordercolor = imagecolorallocate($im, 0, 0, 0);
$color1 = imagecolorallocate($im, 255, 0, 0);
$color2 = imagecolorallocate($im, 0, 255, 0);
$color3 = imagecolorallocate($im, 0, 0, 255);
imagefilledrectangle($im, 0, 0, 199, 149, $bgcolor);
imagerectangle($im, 0, 0, 199, 149, $bordercolor);
imagefilledrectangle($im, 30, 100, 60, 148, $color1);
imagefilledrectangle($im, 80, 80, 110, 148, $color2);
imagefilledrectangle($im, 130, 40, 160, 148, $color3);
//Output it
$pdf->GDImage($im, 120, 25, 40);
imagedestroy($im);
$pdf->Output();
?>
您必须使用
MemImage
功能来显示图像的blob
数据
$pdf->MemImage($url, 50, 30);
编辑
来源
<?php
require('fpdf.php');
//Stream handler to read from global variables
class VariableStream
{
var $varname;
var $position;
function stream_open($path, $mode, $options, &$opened_path)
{
$url = parse_url($path);
$this->varname = $url['host'];
if(!isset($GLOBALS[$this->varname]))
{
trigger_error('Global variable '.$this->varname.' does not exist', E_USER_WARNING);
return false;
}
$this->position = 0;
return true;
}
function stream_read($count)
{
$ret = substr($GLOBALS[$this->varname], $this->position, $count);
$this->position += strlen($ret);
return $ret;
}
function stream_eof()
{
return $this->position >= strlen($GLOBALS[$this->varname]);
}
function stream_tell()
{
return $this->position;
}
function stream_seek($offset, $whence)
{
if($whence==SEEK_SET)
{
$this->position = $offset;
return true;
}
return false;
}
function stream_stat()
{
return array();
}
}
class PDF_MemImage extends FPDF
{
function PDF_MemImage($orientation='P', $unit='mm', $format='A4')
{
$this->FPDF($orientation, $unit, $format);
//Register var stream protocol
stream_wrapper_register('var', 'VariableStream');
}
function MemImage($data, $x=null, $y=null, $w=0, $h=0, $link='')
{
//Display the image contained in $data
$v = 'img'.md5($data);
$GLOBALS[$v] = $data;
$a = getimagesize('var://'.$v);
if(!$a)
$this->Error('Invalid image data');
$type = substr(strstr($a['mime'],'/'),1);
$this->Image('var://'.$v, $x, $y, $w, $h, $type, $link);
unset($GLOBALS[$v]);
}
function GDImage($im, $x=null, $y=null, $w=0, $h=0, $link='')
{
//Display the GD image associated to $im
ob_start();
imagepng($im);
$data = ob_get_clean();
$this->MemImage($data, $x, $y, $w, $h, $link);
}
}
?>
范例
<?php
require('mem_image.php');
$pdf = new PDF_MemImage();
$pdf->AddPage();
//Load an image into a variable
$logo = file_get_contents('logo.jpg');
//Output it
$pdf->MemImage($logo, 50, 30);
//Create a GD graphics
$im = imagecreate(200, 150);
$bgcolor = imagecolorallocate($im, 255, 255, 255);
$bordercolor = imagecolorallocate($im, 0, 0, 0);
$color1 = imagecolorallocate($im, 255, 0, 0);
$color2 = imagecolorallocate($im, 0, 255, 0);
$color3 = imagecolorallocate($im, 0, 0, 255);
imagefilledrectangle($im, 0, 0, 199, 149, $bgcolor);
imagerectangle($im, 0, 0, 199, 149, $bordercolor);
imagefilledrectangle($im, 30, 100, 60, 148, $color1);
imagefilledrectangle($im, 80, 80, 110, 148, $color2);
imagefilledrectangle($im, 130, 40, 160, 148, $color3);
//Output it
$pdf->GDImage($im, 120, 25, 40);
imagedestroy($im);
$pdf->Output();
?>
谢谢,但它显示了致命错误:调用未定义的方法FPDF::MemImage()@DominicSeb-Ohh,忘记包含所需的函数,转到提供的url,它包含完整的代码。:)嘿,谢谢..但是我下载了整个代码,我做了如下操作..包括了所需的函数,但仍然是相同的错误谢谢,但上面说的是致命错误:调用未定义的方法FPDF::MemImage()@DominicSeb Ohh,忘记包含必需的函数,转到提供的url,它包含完整的代码。:)嘿,谢谢..但是我下载了完整的代码,我做了如下操作..包含必需的函数,但仍然是相同的错误