php多文件上传示例

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>无标题文档</title>
</head>

<body>
请选择要上传的文件
<form action="" method="post" enctype="multipart/form-data">
    <table id="up_table" border="1" bgcolor="f0f0f0">
        <tbody id="auto">
        <tr id="show">
            <td>上传文件</td>
            <td><input name="u_file[]" type="file"></td>
        </tr>
        <tr>
            <td>上传文件</td>
            <td><input name="u_file[]" type="file"></td>
        </tr>
        </tbody>
        <tr>
            <td colspan="4"><input type="submit" value="上传"/></td>
        </tr>
    </table>
</form>
<?php
if (!empty($_FILES['u_file']['name'])) {
    $file_name = $_FILES['u_file']['name'];
    $file_tmp_name = $_FILES['u_file']['tmp_name'];
    for ($i = 0; $i < count($file_name); $i++) {
        if ($file_name[$i] != '') {
            move_uploaded_file($file_tmp_name[$i], $i . $file_name[$i]);
            echo '文件' . $file_name[$i] . '上传成功。更名为' . $i . $file_name[$i] . '<br>';
        }
    }
}
?>
</body>
</html>

 

posted @ 2013-04-24 10:20  海阔天空XM  阅读(166)  评论(0编辑  收藏  举报