程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> php基礎練習--多文件上傳,

php基礎練習--多文件上傳,

編輯:關於PHP編程

php基礎練習--多文件上傳,


<html>
<head>
    <meta charset="utf-8">
    <title>index_uploads</title>
</head>
<body>
    <form action="uploads.php" method="post" enctype="multipart/form-data">
        <input type="file" name="file[]">
        <br>
        <input type="file" name="file[]">
        <br>
        <input type="submit" value="uploads">
    </form>
</body>
</html>

index_uploads.php

  

<?php
            header("content-type:text/html;charset=utf-8");
            echo "<pre>";
            print_r($_FILES);
            echo "</pre>";

            $count = count($_FILES['file']['name']);

            for ($i = 0; $i < $count; $i++) {
                $tmpfile = $_FILES['file']['tmp_name'][$i];
                $filefix = array_pop(explode(".", $_FILES['file']['name'][$i]));
                $dstfile = "uploads/files/".time()."_".mt_rand().".".$filefix;

                if (move_uploaded_file($tmpfile, $dstfile)) {
                    echo "<script>alert('succeed!');window.location.href='index_uploads.php';</script>";
                } else {
                    echo "<script>alert('fail!');window.location.href='index_uploads.php';</script>";
                }
            }

uploads.php

  

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved