<?php if(isset($_GET['type'])){ $path="attachment/".date("Ymd"); if($_GET['type']=="0"){ if(!file_exists($path)){ mkdir($path); } if(move_uploaded_file($_FILES["file"]["tmp_name"], $path."/" . $_FILES["file"]["name"])){ echo "<span style=\"color:red\">上传成功!</span> <a href=\"index.php\">返回</a>"; }else{ echo "<span style=\"color:red\">上传失败!</span> <a href=\"index.php\">返回</a>"; } }else{ if(unlink($path."/".$_GET["filename"])){ echo "<span style=\"color:red\">删除成功!</span> <a href=\"index.php\">返回</a>"; }else{ echo "<span style=\"color:red\">删除失败!</span> <a href=\"index.php\">返回</a>"; } } } ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>上传文件管理</title> <style type="text/css"> a{ color:#000; text-decoration:none; } </style> </head> <body> <form action="?type=0" method="post" enctype="multipart/form-data" name="form1"> <label for="file"></label> <input type="file" name="file" id="file" style="width:348px"> <input type="submit" name="button" id="button" value="上传"> </form> <br /> <table width="400" border="1" cellpadding="0" cellspacing="0" style="text-align:center"> <tr> <td width="70%">文件名</td> <td colspan="2">操作</td> </tr> <?php $path="attachment/".date("Ymd"); $filesnames = scandir($path); foreach ($filesnames as $filename) { if($filename!="." && $filename !=".."){ $name= iconv("GBK","UTF-8//IGNORE",$filename); echo "<tr>"; echo "<td style=\"text-align:left\">".$name."</td>"; echo "<td><a href=\"".$path."/".$name."\">下载</a></td>"; echo "<td><a href=\"?type=1&filename=".$name."\">删除</a></td>"; echo "</tr>"; } } ?> </table> </body> </html>
이상에서는 다양한 측면을 포함한 간단한 업로드 파일 관리 시스템을 소개했습니다. PHP 튜토리얼에 관심이 있는 친구들에게 도움이 되기를 바랍니다.