将图像保存到数据库
$query =$myClass->query("insert into tblImage(document) values(".base64_encode(file_get_contents($_FILES['imageFile']["tmp_name"])).")");
从数据库显示图像
$image =$myClass->query("select document from tblImage where code=1");
$output_bin_string = base64_decode($image[0]['thumbDocument']);
header("Content-Type: image/jpeg");
header("Content-Length: " . strlen($output_bin_string));
echo $output_bin_string;
我可以将图像保存到文件,然后保存到数据库
$image=$myClass->query('select document form tblImage where code=1' );
$source = imagecreatefromstring(base64_decode($image[0]["document"])) ;
$rotate = imagerotate($source,$degrees,0);
imagejpeg($rotate,'tmp/1.jpg');
$image =$myClass->query("update tblImage set document='".base64_encode(file_get_contents('tmp/1.jpg'))."' where code=1");
问题:有一种方法可以旋转图像并保存到数据库而无需像这样保存图像
$image=$myClass->query('select document form tblImage where code=1' );
$source = imagecreatefromstring(base64_decode($image[0]["document"])) ;
$rotate = imagerotate($source,$degrees,0);
$image =$myClass->query("update tblImage set document='".base64_encode($rotate)."' where code=1");
此代码说错误:base64_encode() expects parameter 1 to be string, resource given