文件上传PHP无法正常工作,我不知道为什么

时间:2012-01-26 15:04:09

标签: php upload file-upload is-uploaded-file

我的HTML表单代码:

        <form action="upload.php" method="GET" enctyped="multipart/form-data">
            <label for="file"> Filename:</label>
            <input type="file" name="loadedFile" id="file"/></br>
            <input type="submit" name="uploadItNow" value="Submit"/>
            hai, this is this the uploader.
        </form>

PHP文件上传器脚本:

if (isset($_GET['uploadItNow'])) // checks if submit button has pressed
{

    if ($_FILES['loadedFile']["error"] > 0)

        echo "Error: ". $_FILES["loadedFile"] ["error"]. "</br>";


    else
    {
        echo "Upload: ". $_FILES["loadedFile"] ["name"]. "</br>";
        echo "Type: ". $_FILES["loadedFile"] ["type"] . "</br>";
        echo "Stored in: " .$_FILES["loadedFile"] ["tmp_name"];
        echo "Size: ". ($_FILES["loadedFile"] ["size"] / 1024). " Kb</br>";

        //Copies file from TEMP_PHP dir to d.default dir
        if (file_exists("." . $_FILES["loadedFile"]["name"]))
        {
            echo $_FILES["loadedFile"]["name"] . " already exists. ";
        }

        else
        {
            move_uploaded_file($_FILES["loadedFile"]["tmp_name"],"." . $_FILES["loadedFile"]["name"]);
            echo "Stored in: " . "upload/" . $_FILES["loadedFile"]["name"];
        }
    }
} 

由于某些原因它不起作用,我的脚本继续使用这段代码:

echo $_FILES["loadedFile"]["name"] . " already exists. ";

4 个答案:

答案 0 :(得分:4)

您需要使用POST以及将“enctype”更改为“enctype”。

<form action="upload.php" method="POST" enctype="multipart/form-data">

答案 1 :(得分:3)

尝试将表单方法更改为POST

<form action="upload.php" method="POST" enctype="multipart/form-data">

答案 2 :(得分:1)

尝试使用POST而不是GET

也许该文件确实存在?你没有考虑路径

答案 3 :(得分:1)

将方法更改为post并将enctype更改为enctype

<form action="upload.php" method="POST" enctype="multipart/form-data">