- 论坛徽章:
- 0
|
w2k下用显示 mysql 中的图片的 问题?
看看我写的
//upload.php
<?
include("../phpconfig/config.inc.php"
if($submit)
{
if($form_data==""||!file_exists($form_data)) die("上传文件失败!"
if(!ereg("image",$form_data_type)) echo "只能上传图片!";
else
{
if(!$fp=fopen($form_data,"rb") die("打开文件失败!"
$data=addslashes(fread($fp,filesize($form_data)));
fclose($fp);
$query="insert into `picture` (`bin_data`,`filetype`) values ('$data','$form_data_type')";
mysql_query($query) or die(mysql_error());
echo "成功保存文件,id=".mysql_insert_id();
}
unlink($form_data);
}
?>;
<html>;
<head>;
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">;
<title>;无标题文档</title>;
</head>;
<body>;
<form action="" method="post" enctype="multipart/form-data" name="form1">;
<input name="MAX_FILE_SIZE" type="hidden" id="MAX_FILE_SIZE" value="1000000">;
<input name="form_data" type="file" id="form_data">;
<input type="submit" name="submit" value="提交">;
</form>;
</body>;
</html>;
//show.php
<?
if($id)
{
include("../phpconfig/config.inc.php"
$query="select bin_data,filetype from picture where id = '$id'";
$result=mysql_query($query) or die(mysql_error());
if(mysql_numrows($result)>;0)
{
$data=mysql_result($result,0,"bin_data"
$type=mysql_result($result,0,"filetype"
header("Content-type: $type"
echo $data;
}
else
{
echo "此图片不存在!";
}
}
?>; |
|