PHP上传单张图片到服务器,如下代码:
- <?php
- session_start();
- include("conn.php");?>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
- <title>上传单图片到服务器并显示 - www.cxybl.com</title>
- </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="<?php echo $myrow[path];?>" width="200" height="150"></td>
- </tr>
- <?php }}?>
- </table>
- </body>
- </html>
conn.php:
- <?php
- $id=mysql_connect('localhost','root','root');
- mysql_select_db("db_database12",$id);
- mysql_query("set names gb2312");
- ?>
index_ok.php:
- <?php
- session_start();
- include("conn.php");?>
- <?php
- if($Submit=="提交"){
- $data=date("Y-m-d");
- $filesize=$_FILES['images']['size'];
- if($filesize>1000000)
- {echo "<script> alert('对不起,您输入的图片太大,不能上传!!'); history.back();</script>";}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 "<meta http-equiv=\"Refresh\" content=\"3;url=index.php\">";
- }else{echo "文件上传失败!!";
- echo "<meta http-equiv=\"Refresh\" content=\"3;url=index.php\">";}
- }}}
- ?>
以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索php
, 服务器
, 图片
, 代码
, com
, www
, php单文件上传
单张图片浏览
单张图片上传插件、jquery 单张图片上传、ueditor单张图片上传、html5上传单张图片、okhttp3上传单张图片,以便于您获取更多的相关知识。
时间: 2024-12-24 21:17:56