<!--
CREATE TABLE ccs_image (
id int(4) unsigned NOT NULL auto_increment,
description varchar(250) default NULL,
bin_data longblob,
filename varchar(50) default NULL,
filesize varchar(50) default NULL,
filetype varchar(50) default NULL,
PRIMARY KEY (id)
)
-->
<HTML>
<HEAD>
<TITLE>
</TITLE></HEAD>
<BODY>
<?php
if (isset($_POST['submit'])) {
$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']
$connect = MYSQL_CONNECT( "localhost", "root","123456" ) or die("不能连接服务器")
mysql_select_db( image) or die("不能连接数据库")
$data = addslashes(fread(fopen($form_data, r), filesize($form_data)))
$result=MYSQL_QUERY("INSERT INTO ccs_image (description,bin_data,filename,filesize,filetype) VALUES ('$form_description','$data','$form_data_name','$form_data_size','$form_data_type')")
$id= mysql_insert_id()
MYSQL_CLOSE()
} else {
?>
<center>
<form method=post action=UPload.php enctype=multipart/form-data>
文件描述:
<br>
<input type=text name=form_description size=40>
<br>
<INPUT TYPE=hidden name=MAX_FILE_SIZE value=1000000>
<br>
<!--File to upload/store in database: -->
请选择上传文件:
<br>
<input type=file name=form_data size=40>
<br>
<input type=submit name=submit value=确定>
</form>
</center>
<?php
}
?>
</BODY>
</HTML>
首先是提交窗口,然后是php上传图片并且返回保存路径,最后是路径,时间等值一起insert进mysql。了解流程后自己去分段找代码,或者拿一整段代码分结构看。否则给一段完整的你也不会改1.php<form action="2.php" method="post" enctype="multipart/form-data" name="f1">
<input type="file" name="myfile"/>
<input type="submit" name="submit"/>
</form>
2.php
<?php
session_start()
echo $_FILES['myfile']['name']
$picture = 'upload/'.$_FILES['myfile']['name']
move_uploaded_file($_FILES['myfile']['tmp_name'] , $picture)
echo $picture
$_SESSION["href"]= $picture
$_SESSION["picture"] = $_FILES["myfile"]['name']
?>
<br/>
<a href="3.php">下一步</a>
3.php
<?php
session_start()
?>
<form action="4.php" method="post" name="f1">
<input type="text" name="title"/>
<input type="submit" value="确定">
</form>
4.php
<?php
session_start()
$title = $_POST["title"]
$dater = date('Y-d-m')
$conn = mysql_connect('localhost' , 'root' , '316520')
if (!mysql_select_db('zzwsd' , $conn)){
echo "error"
}
$id = 0
$sql = "select * from zzwsd"
$query = mysql_query($sql)
while ($row = mysql_fetch_array($query)){
$id = $row[0]
$id ++
}
$sql = "INSERT INTO zzwsd (id , title , picture , href , dater) VALUES ('$id' , '$title' , '$_SESSION[picture]' , '$_SESSION[href]' , '$dater')"
$query = mysql_query($sql)
echo "导入成功<br/>"
echo "<a href=zzwsd.php>前台展示</a><br/>"
$sql = "select * from zzwsd"
$query = mysql_query ($sql)
$i = 0
while ($row = mysql_fetch_array($query)){
$i ++
echo "第".$i."条记录: ".$row[0]." ".$row[1]." ".$row[2]." ".$row[3]." ".$row[4]." "."<br/><br/>"
}
?>
del.php
<?php
echo "这是删除页面 ".$_GET[id]
?>
mod.php
<?php
echo "这修改页面 ".$_GET[id]
?>
zzwsd.php
<?php
$cho = 101
echo "这里是前台"
?>
<br/><br/>
<div style="margin-left:50pxwidth:1000pxbackground:#CCCCFF">
<?php
$conn = mysql_connect('localhost' , 'root' , '316520')
if(!mysql_select_db('zzwsd' , $conn)){
echo "链接数据库失败"
}
$i = 0
$sql = "select * from zzwsd limit $i , 30"
$query = mysql_query($sql)
while ($row = mysql_fetch_array($query)){
?>
<div style="margin-left:10pxmargin-top:20pxwidth:220pxheight:200pxfloat:left">
<img src=<?php echo $row[3]?>width=160px height=200px style="float:left"/>
<div style="float:leftwidth:60px">
<?php if($cho == 101){ ?>
<br/>
<a href=<?php echo "del.php?id=".$row[0] ?>target="_self">删除</a>
<br/>
<br/>
<a href=<?php echo "mod.php?id=".$row[0] ?>target="_self">修改</a>
<?php }else{ ?>
<?php } ?>
</div>
</div>
<?php
}
?>
</div>
这是我当初学的时候练手的。拿去看看吧, 用mysql自己创建数据库和里面的字段就可以了,注意别乱码了
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)