继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

PHP文件上传代码实例

大话西游666
关注TA
已关注
手记 209
粉丝 140
获赞 620
<!DOCTYPE=html>
<html>
<head>
    <title>文件上传</title>
    <meta charset='gb2312' />
    <style type="text/css">
        td{border:1px #0066ff solid;}
        table{border-collapse:collapse;}
    </style>
    <script>
        function aa()
        {
            alert("deletefile!"); 
        }
    </script>
</head>
<body>
    <form action="" method="post" enctype="multipart/form-data">
        <input type="file" name="upfile" />
        <br /><br />
        <input type="submit" name="submit" value="上传" />
    </form>
<br><br><br>
 
 
<?php       
        if(!empty($_FILES[upfile][name]))
        {
            $fileinfo = $_FILES[upfile];
            $type = strstr($fileinfo['name'],".");
            echo "上传的文件类型是: ".$type;
            $path = "./Uploads/".$_FILES["upfile"]["name"];
            if(move_uploaded_file($fileinfo['tmp_name'],$path))
            {
                echo "<script>alert('文件上传成功。');</script>";
            }
            echo "<hr />";
            echo "<hr />";
            foreach($_FILES['upfile'] as $name=>$value)
            {
                echo $name.'='.$value.'<br>';
                //echo 'asds'.$value.'<br>';
            }
            echo "<hr />";
        }
            //上传成功后浏览目录
            if(is_dir("uploads/"))
            {
                $dir = scandir("uploads/");
                echo "<form action='deletefile.php' method='get'>";
                echo "<table>";
                foreach($dir as $value)
                    if($value!='.' and $value!='..')                 
                        echo "<tr><td><a href='"."./Uploads/".$value."'>".$value."</a>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;<a href='deletefile.php?name=".$value."' onclick='javascript:return confirm(\"真的要删除这个文件吗?\");'>删除</a>&nbsp;</td>";
                 
                echo "</table>   ";
                echo "</form>";
            }
            else
            {
                echo "目录路径错误!";
            }
 
             
         
?>
<!-- &quot;-->
</body>
</html>


打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP