PHP文件上传没有任何作用

use*_*574 0 php forms upload file

我之前有过几个上传表单,但是,即使在几乎复制我之前的代码之后,这似乎也不起作用,我更喜欢在一个php脚本文件中完成所有操作,所以它都是在这个单个文件中生成的.

我的表格:

<form action="" method="post" enctype="multipart/form-data">
    <ul>
        <li>
            <label for="file">File : </label>
            <input type="file" id="file" name="file" required="required" />
        </li>
        <li>
            <input type="submit" value="Upload" />
        </li>
    </ul>
</form>
Run Code Online (Sandbox Code Playgroud)

我的php上传:

if(!empty($_POST['file']))
{
    echo "Found.";
    $exts = array("gif", "jpeg", "jpg", "png");
    $temp = explode(".", $_FILES["file"]["name"]);
    $ext = end($temp);
    if((($_FILES["file"]["type"] == "image/gif")
    || ($_FILES["file"]["type"] == "image/jpeg")
    || ($_FILES["file"]["type"] == "image/jpg")
    || ($_FILES["file"]["type"] == "image/pjpeg")
    || ($_FILES["file"]["type"] == "image/x-png")
    || ($_FILES["file"]["type"] == "image/png"))
    && ($_FILES["file"]["size"] < 20000)
    && in_array($ext, $exts))
    {
        if($_FILES["file"]["error"] > 0)
        {
            $result = "Error Code: " . $_FILES["file"]["error"] . "<br />";
        }
        else
        {
            $scandir = scandir("/images/news/");
            $newname = (count($scandir-2)) . $ext;
            move_uploaded_file($_FILES["file"]["tmp_name"],"/images/news/" . $newname);
            $ulink = "/images/news/" . $newname;
            $result = "Success, please copy your link below";
        }
    }
    else
    {
        $result = "Error.";
    }
}
Run Code Online (Sandbox Code Playgroud)

当我上传.png图片时,页面似乎只是刷新,我已经把它echo "Found.";放在那里检查它是否有任何东西,$_POST["file"]但似乎没有任何东西.

我不明白为什么页面没有正确提交.我已经改变action="",以action="upload.php"确保它指向同一页面,但仍然一无所获.

Spr*_*gie 6

$_FILES['file']而不是$_POST['file'].

有关$ _FILES的更多信息,请访问http://www.php.net/manual/en/features.file-upload.post-method.php