使用PHP和多个输入表单上传多个文件

时间:2014-04-05 21:04:14

标签: php html uploading

我正在尝试一次上传多个文件,当我运行表单时,我得到一个空白屏幕。 PHP错误不提供任何有关错误的信息。我已经使用PHP文档网站作为资源,我仍然遇到麻烦使这项工作。任何帮助将不胜感激!这是代码:

PHP:

$file_ary = reArrayFiles($_FILES['file']);

    foreach($file_ary as $ufile) {

        $allowedExts = array("gif", "jpeg", "jpg", "png", "bmp", "ico", "swf", "txt", "html", "htm", "css", "js", "c", "cpp", "lua", "py", "tar", "zip", "rar", "gz", "7z", "bz2", "tgz");
        $temp = explode(".", $ufile["name"]);
        $extension = end($temp);
        if ((($ufile["type"] == "image/gif")
        || ($ufile["type"] == "image/x-gif")
        || ($ufile["type"] == "image/jpeg")
        || ($ufile["type"] == "image/x-jpeg")
        || ($ufile["type"] == "image/x-jpg")
        || ($ufile["type"] == "image/jpg")
        || ($ufile["type"] == "image/pjpeg")
        || ($ufile["type"] == "image/x-png")
        || ($ufile["type"] == "image/bmp")
        || ($ufile["type"] == "image/x-icon")
        || ($ufile["type"] == "text/css")
        || ($ufile["type"] == "application/octet-stream")
        || ($ufile["type"] == "text/html")
        || ($ufile["type"] == "text/htm")
        || ($ufile["type"] == "text/plain")
        || ($ufile["type"] == "application/octet-stream")
        || ($ufile["type"] == "application/x-gunzip")
        || ($ufile["type"] == "application/x-gzip-compressed")
        || ($ufile["type"] == "application/x-rar-compressed")
        || ($ufile["type"] == "application/x-rar")
        || ($ufile["type"] == "application/octet-stream")
        || ($ufile["type"] == "application/x-7z-compressed")
        || ($ufile["type"] == "application/x-7z")
        || ($ufile["type"] == "application/x-compress")
        || ($ufile["type"] == "application/x-compressed")
        || ($ufile["type"] == "application/x-tar")
        || ($ufile["type"] == "application/x-tar-compressed")
        || ($ufile["type"] == "application/x-gtar")
        || ($ufile["type"] == "application/x-tgz")
        || ($ufile["type"] == "application/tgz")
        || ($ufile["type"] == "application/tar")
        || ($ufile["type"] == "application/gzip")
        || ($ufile["type"] == "application/x-gzip")
        || ($ufile["type"] == "application/x-zip")
        || ($ufile["type"] == "application/zip")
        || ($ufile["type"] == "application/x-zip-compressed")
        || ($ufile["type"] == "text/c")
        || ($ufile["type"] == "text/cpp")
        || ($ufile["type"] == "text/lua")
        || ($ufile["type"] == "text/py")
        || ($ufile["type"] == "text/x-lua")
        || ($ufile["type"] == "text/x-c")
        || ($ufile["type"] == "text/x-cpp")
        || ($ufile["type"] == "application/x-python")
        || ($ufile["type"] == "text/x-python")
        || ($ufile["type"] == "text/python")
        || ($ufile["type"] == "application/x-compressed")
        || ($ufile["type"] == "text/javascript")
        || ($ufile["type"] == "application/x-javascript")
        || ($ufile["type"] == "application/bzip2")
        || ($ufile["type"] == "application/x-bzip")
        || ($ufile["type"] == "application/x-bz2")
        || ($ufile["type"] == "application/octet-stream")       
        || ($ufile["type"] == "image/png"))
        && ($ufile["size"] < $user_max_upload)
        && in_array($extension, $allowedExts))
        {
            if ($ufile["error"] > 0)
            {
                echo "<div class='text'>" . $ufile["name"] . ": Return Code: " . $ufile["error"] . "<br></div>";
            }
            else
            {
                if(isset($_GET['p']))
                {
                    $path = $_GET['p'];
                    if(stristr($path, "../") == true)
                    {
                        header("Location: ctrl.php?action=backtracking_error");
                    }
                    else if (file_exists("users/$username/$path/" . $ufile["name"]))
                    {
                        echo "Error: file exists.";
                    }
                    else
                    {
                        $usage = file_get_contents("users/$username.usage");
                        $usage = $usage + $ufile["size"];
                        if($usage > $user_max_webspace) {
                            echo "Error: Exceeding max webspace usage.";
                        }
                        else
                        {
                            $filelist = file_get_contents("users/$username.files");
                            file_put_contents("users/$username.usage", $usage);
                            move_uploaded_file($ufile["tmp_name"],
                            "users/$username/$path/" . $ufile["name"]);
                            file_put_contents("users/$username.files", $ufile["name"] . "<br />\n" . $filelist);
                            header("Location: ctrl.php");
                        }
                    }
                }
                else
                {
                    if (file_exists("users/$username/" . $ufile["name"]))
                    {
                        echo "Error: " . $ufile["name"] . " exists.";
                    }
                    else
                    {
                        $usage = file_get_contents("users/$username.usage");
                        $usage = $usage + $ufile["size"];
                        if($usage > $user_max_webspace) {
                            echo "Error: Exceeding max webspace usage.";
                        }
                        else
                        {
                            file_put_contents("users/$username.usage", $usage);
                            move_uploaded_file($ufile["tmp_name"],
                            "users/$username/" . $ufile["name"]);
                            header("Location: ctrl.php");
                        }
                    }
                }
            }
        }
        else
        {
            echo "<div class='text'>Error: " . $ufile["name"] . " is too large, or is a invalid filetype</div>";
        }
    }

HTML:

    <form action="uploadmulti.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file[]" id="file" multiple><br>
<input type="submit" name="submit" value="Upload">
</form>

0 个答案:

没有答案