无法上传php中的文件

时间:2016-04-28 05:32:16

标签: php file upload

我尝试了很多但是无法获得解决方案请帮助我,因为我无法上传我的文件代码如下所示:

<?php
$allowedExts = array("PSD", "JPG", "JPEG", "GIF", "PNG", "AI", "ZIP", "RAR", "PDF", "DOC", "DOCX", "XLS", "XLSX", "PPT");
    $extension = pathinfo( $_FILES["file"]["name"], PATHINFO_EXTENSION);

    if (($_FILES["file"]["size"] < 200000) && array_search($extension, $allowedExts)!==false) {
        if ($_FILES["file"]["error"] > 0)
        {
            echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
        }
        else
        {
            echo "Upload: " . $_FILES["file"]["name"] . "<br />";
            echo "Type: " . $_FILES["file"]["type"] . "<br />";
            echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br/>";
            echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

            if (file_exists("uploaded_files/" . $_FILES["file"]["name"]))
            {
                echo $_FILES["file"]["name"] . " already exists. ";
            }
            else
            {
                move_uploaded_file($_FILES["file"]["tmp_name"],
                "common/uploaded_files" . $_FILES["file"]["name"]);
                echo "Stored in: " . "common/uploaded_files" . $_FILES["file"]["name"];
            }
        }
    } else {
        echo "Invalid file";
    }

    ?>

下面是我的php表单代码:

<input type ="file" name= "file" id ="file"/>

2 个答案:

答案 0 :(得分:0)

使用以下代码供您参考..

//SASS Code
$color:#ff0099;
$complement:complement($color);
//Returns the complement of a color.
$invert:invert($color);//Returns the inverse of a color.
.complement{background:$complement;}
.invert{background:$invert;}

//CSS
.complement {
    background: #00ff66;//Same Color Code
}

.invert {
    background: #00ff66;//Same Color Code
}

答案 1 :(得分:0)

您的allowedExts与小写不匹配,请尝试这个小修改。

$extension = strtoupper(pathinfo( $_FILES["file"]["name"], PATHINFO_EXTENSION));