【问题标题】:html tag causing unexpected end of file in .php file [closed]html标签导致.php文件中的文件意外结束[关闭]
【发布时间】:2014-05-29 14:06:01
【问题描述】:

当我在浏览器上使用 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>

【问题讨论】:

  • 您的{} 字符不平衡。
  • 如果if (isset($_POST["submit"])),您忘记关闭它

标签: php html file-upload eof


【解决方案1】:

您在 php 代码中缺少第一个 if 的结束 }

【讨论】:

  • 是的,找到了。感谢大家。错过了就觉得很愚蠢
猜你喜欢
  • 1970-01-01
  • 2021-05-22
  • 1970-01-01
  • 2012-06-10
  • 1970-01-01
  • 1970-01-01
  • 2014-06-18
相关资源
最近更新 更多