很奇怪,直接用file_get_contents存入数据库成功后,结果读取的时候图片不能显示,后来解决方法是什么!!是用了下base64编码。。。不多说直接上图。 1.这是upload.php ? php include ('./conn.php' ); if ( $_POST ['submit' ]) { if ( $_FILES ['image'][' 很奇怪,直接用file_get_contents存入数据库成功后,结果读取的时候图片不能显示,后来解决方法是什么!!是用了下base64编码。。。不多说直接上图。1.这是upload.phpinclude('./conn.php');if ($_POST['submit']) { if ($_FILES['image']['size']) { $names = $_FILES['image']['name']; $arr = explode('.', $names); $name = $arr[0]; //图片名称 $date = date('Y-m-d H:i:s'); //上传日期 $fp = fopen($_FILES['image']['tmp_name'], 'rb'); $type = $_FILES['image']['type']; $file_uploads = file_get_contents($_FILES['image']['tmp_name']); $file_uploads = base64_encode($file_uploads); if (!$fp) { showInfo('读取图片失败!'); } else { if ($image) { $q = "insert into image (name, pic, type, date) values ('$name','$file_uploads','$type','$date')"; $result = mysql_query($q); if ($result) { showInfo('上传成功!'); } else { showInfo('上传失败!'); } mysql_close($link); } else { showInfo('请选择要上传的文件!'); } } } else { showInfo('请选择要上传的文件!'); }}function showInfo($info){ echo "";}?>登录后复制2.image.php用于从数据库中读取图片include('./conn.php');$id = $_GET['id'];$sql = "select * from image where id='$id'";$result = mysql_query($sql);if (!$result) die("读取图片失败!");$num = mysql_num_rows($result);if ($num die("暂无图片");$obj = mysql_fetch_object($result);$data = base64_decode($obj->pic); //Base64解码$type = mysql_result($result, 0, 'type');header("Content-type: $type");echo $data;?>登录后复制3.show.php显示和上传图片include('./conn.php');?> "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">登录后复制 最后运行结果: 总结:网上的都是坑爹么?谁有其他不用base64编码的方法能否告知?
09-14 20:59