PHP 完整图片调用代码
1 index.php:
<html>
<head>
<title>公告信息管理</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="css/style.css" rel="stylesheet">
</head>
<body>
<table width="80%" border="1" align="center" llpadding="1" bordercolor="#FFFFFF" bgcolor="#c17e50">
<?php
$conn=mysql_connect("localhost","root","") or die("数据库服务器连接错误".mysql_error());
mysql_select_db("binary_data",$conn) or die("数据库访问错误".mysql_error());
mysql_query("set names gb2312");
/* $_GET[page]为当前页,如果$_GET[page]为空,则初始化为1 */
if ($_GET[page]==""){
$_GET[page]=1;}
if (is_numeric($_GET[page])){
$page_size=9; //每页显示4条记录
$query="select count(*) as total from binary_data order by id desc";
$result=mysql_query($query); //查询符合条件的记录总条数
$message_count=mysql_result($result,0,"total"); //要显示的总记录数
$page_count=ceil($message_count/$page_size); //根据记录总数除以每页显示的记录数求出所分的页数
$offset=($_GET[page]-1)*$page_size; //计算下一页从第几条数据开始循环
$sql=mysql_query("select * from binary_data order by id desc limit $offset, $page_size");
$row=mysql_fetch_object($sql);
if(!$row){
echo "<font color='red'>暂无公告信息!</font>";
}
$count = 1;
while($row=mysql_fetch_object($sql))
{
if($count%4 == 1)
{
echo '<tr>';
}
echo '<td width="25%"><table width="100%" height="100%" border="1" align="center" cellspacing="0" cellpadding="0">
<tr>
<td height="200" align="center" bgcolor="#FFFFFF"><a href=" '. $row->img_url . ' ">'."<img style='style:height:190px;width:190px;' src='get_data.php?id=".$row->id."' onmouseover='see_big(".$row->id.")' />".'</td>
</tr>
<tr>
<td align=center>'. $row->img_name . '</td>
</tr>
</table>
</td>';
if($count%4 == 0)
{
echo '</tr>';
}
$count +=1;
if ($count%4 == 0)
{
echo "<br/>";
$count = 0;
}
}
}
?>
</table>
<br>
<table width="80%" border="1" align="center" llpadding="1" bordercolor="#FFFFFF" bgcolor="#c17e50">
<tr>
<!-- 翻页条 -->
<td width="37%"> 页次:<?php echo $_GET[page];?>/<?php echo $page_count;?>页 记录:<?php echo $message_count;?> 条 </td>
<td width="63%" align="right">
<?php
/* 如果当前页不是首页 */
if($_GET[page]!=1){
/* 显示“首页”超链接 */
echo "<a href=007.php?page=1>首页</a> ";
/* 显示“上一页”超链接 */
echo "<a href=007.php?page=".($_GET[page]-1).">上一页</a> ";
}
/* 如果当前页不是尾页 */
if($_GET[page]<$page_count){
/* 显示“下一页”超链接 */
echo "<a href=007.php?page=".($_GET[page]+1).">下一页</a> ";
/* 显示“尾页”超链接 */
echo "<a href=007.php?page=".$page_count.">尾页</a>";
}
mysql_free_result($sql);
mysql_close($conn);
?> </td>
</tr>
</table>
</body>
</html>
2 get_data.php:
<?php
if(isset($_GET['id'])) {
$id = $_GET['id'];
$connect = MYSQL_CONNECT("localhost", "root", "") or die("Unable to connect to MySQL server");
mysql_select_db("binary_data") or die("Unable to select database");
$query = "select bin_data,filetype from binary_data where id=$id";
$result = @MYSQL_QUERY($query);
$out=mysql_fetch_array($result);
$data=$out["bin_data"];
$type=$out["filetype"];
Header( "Content-type: $type");
echo $data;
}
if(isset($_GET["pic_id"]))
{
$pic_id = $_GET['pic_id'];
$connect = MYSQL_CONNECT("localhost", "root", "") or die("Unable to connect to MySQL server");
mysql_select_db("binary_data") or die("Unable to select database");
$query = "select * from binary_data where id=$pic_id";
$result = @MYSQL_QUERY($query);
$out=mysql_fetch_array($result);
echo $out["id"];
}
?>
3 addnews.php:
<html>
<head>
<title>公告信息管理</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="css/style.css" rel="stylesheet">
</head>
<body>
<script language="javascript">
function check(form){
if(form.form_data.value==""){
alert("请输入图片!");form.form_data.focus();return false;
}
if(form.imgname.value==""){
alert("请输入名称!");form.imgname.focus();return false;
}
if(form.imgurl.value==""){
alert("请输入链接!");form.imgurl.focus();return false;
}
if(form.imgprice.value==""){
alert("请输入价格!");form.imgprice.focus();return false;
}
form.Submit();
}
</script>
<form method="post" action="faa2.php" enctype="multipart/form-data">
<table width="50%" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2"><strong>商品发布页面</strong></td>
</tr>
<tr>
<td width="19%">图片</td>
<td width="81%"><label>
<input type="file" name="form_data" size="40">
</label></td>
</tr>
<tr>
<td>名称</td>
<td><label>
<input type="text" name="imgname">
</label></td>
</tr>
<tr>
<td>链接</td>
<td><label>
<input type="text" name="imgurl">
</label></td>
</tr>
<tr>
<td>价格</td>
<td><label>
<input type="text" name="imgprice">
</label></td>
</tr>
<tr>
<td>类别</td>
<td><label>
<select name="select" size="value">
<option value="男士" selected>男士</option>
<option value="女士" >女士</option>
<option value="动物" >动物</option>
<option value="百货" >百货</option>
</select>
</label></td>
</tr>
<tr>
<td colspan="2"> <div align="center">
<label>
<label>
<input type="submit" name="Submit" value="提交" onClick="return check(form);">
</label>
<input name="Submit2" type="reset" id="Submit2" value="重置">
</label>
</div></td>
</tr>
</table>
</form>
</body>
</html>
4 faa2.php:
<?php
$imgname = $_POST['imgname'];
$imgurl = $_POST['imgurl'];
$imgprice = $_POST['imgprice'];
$imgsel = $_POST['select'];
$form_description = $_POST['form_description'];
$form_data_name = $_FILES['form_data']['name'];
$form_data_size = $_FILES['form_data']['size'];
$form_data_type = $_FILES['form_data']['type'];
$form_data = $_FILES['form_data']['tmp_name'];
//echo "winson";
// �B�ӵ��Y�ώ�
$connect = MYSQL_CONNECT( "localhost", "root", "") or die("Unable to connect to MySQL server");
mysql_select_db("binary_data") or die("Unable to select database");
$data = addslashes(fread(fopen($form_data, "r"), filesize($form_data)));
$imgname = addslashes($imgname);
$imgsel = addslashes($imgsel);
//echo "mysqlPicture=".$data;
$result=MYSQL_QUERY( "INSERT INTO binary_data (description,bin_data,filename,filesize,filetype,img_name,img_url,img_price,img_sel) VALUES ('$form_description','$data','$form_data_name','$form_data_size','$form_data_type','$imgname','$imgurl','$imgprice','$imgsel')");
echo "<script>alert('添加信息成功!');window.location.href='addnews.php';</script>";
MYSQL_CLOSE();
?>
浙公网安备 33010602011771号