PHP上传单张图片
程序员文章站
2022-04-11 18:03:29
...
PHP上传单张图片到服务器,如下代码:
- php
- session_start();
- include("conn.php");?>
- html>
- head>
- meta http-equiv="Content-Type" content="text/html; charset=gb2312">
- title>上传单图片到服务器并显示 - www.cxybl.comtitle>
- head>
- body>
- table width="355" height="240" border="0" align="center" cellpadding="0" cellspacing="0">
- tr>
- td width="106" height="100"> td>
- td width="196"> td>
- td width="31"> td>
- tr>
- form name="form1" method="post" action="index_ok.php" enctype="multipart/form-data">
- tr>
- td height="30" align="center"> td>
- td valign="middle">input name="images" type="file" id="images2" size="15">
- input type="hidden" name="MAX_FILE_SIZE" value="30000"> td>
- td> td>
- tr>
- tr>
- td height="55"> td>
- td>input type="submit" name="Submit" value="提交">td>
- td> td>
- tr>
- form>
- tr>
- td height="55"> td>
- td> td>
- td> td>
- tr>
- table>
- table width="355" border="1" align="center" cellpadding="0" cellspacing="0">
- php $query="select * from tb_image2 where id order by data desc limit 2";
- $result=mysql_query($query);
- if($result==true){
- while($myrow=mysql_fetch_array($result)){
- ?>tr>
- td width="100" align="center">php echo $myrow[data];?>td>
- td width="255" align="center">img src="" width="200" height="150">td>
- tr>
- php }}?>
- table>
- body>
- html>
conn.php:
- $id=mysql_connect('localhost','root','root');
- mysql_select_db("db_database12",$id);
- mysql_query("set names gb2312");
- ?>
index_ok.php:
- session_start();
- include("conn.php");?>
- if($Submit=="提交"){
- $data=date("Y-m-d");
- $filesize=$_FILES['images']['size'];
- if($filesize>1000000)
- {echo "";}else{
- $path = 'upfiles/'. $_FILES['images']['name'];
- if (move_uploaded_file($_FILES['images']['tmp_name'],$path)) {
- $query1="insert into tb_image2(path,data,image_name)values('$path','$data','$images')";
- $result1=mysql_query($query1);
- if($result1=true){
- echo "上传成功!!";
- echo "";
- }else{echo "文件上传失败!!";
- echo "";}
- }}}
- ?>
上一篇: phpBB BBcode处理的漏洞
下一篇: 有关CSS浮动和定位定义和用法介绍