详细解决方案
PHP上传文件到服务器 并显示
热度:32 发布时间:2024-01-21 17:12:41.0
1 |
先说一下php环境搭建,我是用的是appserv 菜鸟级产品 直接安装就可以了 注意记住mysql的密码 mysql的 帐号是root |
01 |
<form name="form1" method="post" action="index_ok.php" enctype="multipart/form-data"> |
03 |
<td height="30" align="center"> </td> |
04 |
<td valign="middle"><input name="images" type="file" id="images2" size="15"> |
05 |
<input type="hidden" name="MAX_FILE_SIZE" value="30000"> </td> |
09 |
<td height="55"> </td> |
10 |
<td><input type="submit" name="Submit" value="提交"></td> |
上传显示提醒页面写入数据库的代码
01 |
<?php session_start(); include("conn/conn.php");?> |
05 |
$filesize=$_FILES['images']['size']; |
06 |
if($filesize>1000000){
echo "<script> alert('对不起,您输入的图片太大,不能上传!!'); history.back();</script>";}else{
|
07 |
$path = 'upfiles/'. $_FILES['images']['name']; |
08 |
if (move_uploaded_file($_FILES['images']['tmp_name'],$path)) {
|
09 |
$query1="insert into tb_image2(path,data,image_name)values('$path','$data','$images')"; |
10 |
$result1=mysql_query($query1); |
13 |
echo "<meta http-equiv=\"Refresh\" content=\"3;url=index.php\">"; |
14 |
}else{
echo "文件上传失败!!"; |
15 |
echo "<meta http-equiv=\"Refresh\" content=\"3;url=index.php\">";} |
所包含的连接数据库的配置文件
2 |
$id=mysql_connect('localhost','root','1'); |
3 |
mysql_select_db("db_database12",$id); |
4 |
mysql_query("set names gb2312"); |
遍历然后显示图片的代码
01 |
<table width="355" border="1" align="center" cellpadding="0" cellspacing="0"> |
02 |
<?php $query="select * from tb_image2"; |
03 |
$result=mysql_query($query); |
05 |
while($myrow=mysql_fetch_array($result)){
|
07 |
<td width="100" align="center"><?php echo $myrow[data];?></td> |
08 |
<td width="255" align="center"><img src="<?php echo $myrow[path];?>" width="200"height="150"></td> |