电脑安全

您当前的位置:主页 > 电脑安全 >

php简单文件上传代码-网络编程

来源:[db:来源]标题:   文件    编辑:电脑技术全能网 时间:2019-09-20 06:24

原标题:php简单文件上传代码-网络编程
   <html><head><title>filemanage</title></head><body><center><p><h2>文件治理</h2></p><br><table border=1><tr size=18><td>文件ID</td><td>文件称号</td><td>文件巨细</td><td>上传时光</td><td>下载</td><td>删除</td></tr><?phpinclude("conn.php");//echo '<table border=1>';$rs=$db->query("select * from filem order by f_id DESC");$i=1;while($row = $rs->fetch_assoc()) {$size=$row['f_size']/1024;echo "<tr><td>".$i++."</td><td>".$row['f_name']."</td><td>".number_format($size, 2, '.', '')."KB</td><td>".$row['f_date']."</td><td><a href=".$row['f_url']." target=_blank>下载</a></td><td><a href=del.php?id=".$row['f_id'].">删除</a></td></tr>"; }echo '</table>';unset($rs);$db->close();?></center><br><br><hr><br><b><h2>uploadfile</h2></b><br><form enctype="multipart/form-data" action="" method="post">抉择上传文件:<br><input name="userfile" type="file"><br><input type="submit" value="发送"></form><?phpif(!$_FILES["userfile"]["name"]) exit;//echo $_FILES['userfile']['type'];if ($_FILES['userfile']['error'] > 0) { echo 'Problem: '; switch ($_FILES['userfile']['error']) { case 1: echo 'File exceeded upload_max_filesize'; break; case 2: echo '不能超越800M'; break; case 3: echo 'File only partially uploaded'; break; case 4: echo 'No file uploaded'; break; } exit; }else{ //检讨上传文件能否在同意上传的范例 $tp = array("gif","jpeg","png","txt","doc","rar","zip","xls","bmp","wmv","mp3","flv","rmvb","avi");if (!in_array(strtolower(substr(strrchr($_FILES['userfile']['name'], '.'),1)), $tp)) { echo '文件范例过错,请从新抉择文件!<br>只同意rar,zip,jpg,gif,txt,png,bmp,xls范例的文件'; exit; } $path="./file/"; //上传门路 if(file_exists($path.$_FILES['userfile']['name'])) //推断文件能否存在 { echo '文件已存在,请变动后从新上传!'; exit; } if($_FILES["userfile"]["name"]) { $file1=$_FILES["userfile"]["name"]; $file2 = $path.$file1; $flag=1; } if($flag) $result=move_uploaded_file($_FILES["userfile"]["tmp_name"],$file2); //特殊留神这里通报给move_uploaded_file的第一个参数为上传到效劳器上的常设文件 if($result) { $time=date("Y-m-d"); // $url=$patch.$name; $size=$_FILES["userfile"]["size"]; include("conn.php"); $rs=$db->query("insert into filem(f_name,f_url,f_date,f_size) values('$file1','$file2','$time','$size')"); // $rs=$db->query($sql); echo "<script language='javascript'>location='index.php';</script>"; } unset($rs); $db->close();}?></body></html>

上一篇:数据库的日期格式转换-网络编程

下一篇:没有了