html标记导致.php文件中意外的文件结束

时间:2014-05-29 06:02:57

标签: php html file-upload eof

当我在浏览器上使用wampserver打开文件时,它说: "解析错误:语法错误,第53行的C:\ wamp \ www \ Tests \ FileUploadPractiseForm.php中的意外文件结束。"

我在文件正文中使用php脚本。

无法弄清问题是什么。 这是代码:

    

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="Submit">

<?php
if (isset($_POST["submit"]))
{
    $name=$_FILES["file"]["name"];
    $tmp_name=$_FILES["file"]["tmp_name"];
    $error=$_FILES["file"]["error"];
    $size=$_FILES["file"]["size"];
    $type=$_FILES["file"]["type"];

    $allowedExts = array("gif", "jpeg", "jpg", "png"); //Specify allowed Extensions
    $temp = explode(".", $name); //Split up file name
    $extension = end($temp); //Assign to last element of array with file-name parts ie extension.

    if ( (($type == "image/gif")||($type == "image/jpeg")||($type == "image/jpeg")||($type == "image/png")||($type == "image/x-png")||($type == "image/pjepg")) && ($size < 1048476) && in_array($extension, $allowedExts) ) //check if its an image, if its less than max size, if its extension is allowed
        {
            if ( $error > 0) 
                {
                    echo "Error: " . $error . "<br>"; //in case there's an upload error
                } 
            else if (isset($name))
                { 
                    if (!empty($name))
                        {
                            $location='upload/';
                            move_uploaded_file($tmp_name, $location.$name);
                            echo "Image Uploaded";  //this if-else section is used to store the file in non-temp location ie "upload" folder
                        }
                }
        }
    else 
        {
            if ($size >= 1048476)
                {
                    echo "Maximum File Size Exceeded";
                }
            else
                {
                    echo "Invalid File Type";
                }
        }
?>

</form>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

您错过了PHP代码中第一个}的结束if