1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
include("conn.php"); $filename = "这里写绝对路径的图片"; $fp=fopen($filename, "rb");
$picture = addslashes(fread($fp, filesize($filename))); $picture = base64_encode($picture);
//fclose($fp);
$query = "insert into data(id,filename,Image) valu es(NULL,'$filename', '$picture');"; $result = mysql_query($query)or die(mysql_error()); echo "存储图片成功。";
//读取图片: include('conn.php'); // 连接数据库查询 $sql="select * from data where id=55"; $result=mysql_query($sql); //$num_results=mysql_num_rows($result); $row=mysql_fetch_object($result); echo stripslashes(base64_decode($row->Image)); mysql_free_result($result); mysql_close($conn); |