语法错误:文件结束

时间:2013-08-14 13:06:33

标签: php

它说,

  

解析错误:语法错误,文件意外结束   第96行/mnt/sdcard/www/parts/background/editProfilePic_Process.php

找不到错误。

以下是代码:

    <?php

session_start();
$site="http://".$_SERVER["HTTP_HOST"]."/";
$root=$_SERVER["DOCUMENT_ROOT"];
if(substr($root,-1)!="/")
{
$root=$root."/";
}


 if(!isset($_SESSION["u"]))
{
header("location:".$site."user");
exit;
} 
 else{
$u=$_SESSION["u"];
}
 if(!isset($_POST["access"]))
{
echo "You cannot access this page";
exit;

} 
?>



<!DOCTYPE html>
<html>
<head>

<?php 
include($root."parts/resources.php");

?>
</head>
<body>

<?php
// header also contents the <noscript> alert 
include($root."parts/header.php");

?>
<div class="wholepage">

<div class="page scatterList">


 <?php 
if(isset($_FILES["profilePic"]))
{
$name=$_FILES["profilePic"]["name"];

if($_FILES["profilePic"]["error"] !== UPLOAD_ERR_OK) {
die("Upload failed with error code ".$_FILES["profilePic"]["error"]); 
} 

if(!getimagesize($_FILES["profilePic"]["tmp_name"]))
{
 exit;
}

$path=$site."img/1/".$u.".jpg";

move_uploaded_file($path, $_FILES["profilePic"]["tmp_name"]);
}
?>

</div> <!-- end of .page -->


</div> <!-- wholepage -->
<!-- FOOTER -->
<?php 
include($root."parts/footer.php");
?>

</body>
</html>

我该怎么做才能摆脱它?

5 个答案:

答案 0 :(得分:1)

您忘记关闭 isset if循环中的大括号。试试这段代码。

<?php

    session_start();
    $site="http://".$_SERVER["HTTP_HOST"]."/";
    $root=$_SERVER["DOCUMENT_ROOT"];
    if(substr($root,-1)!="/")
    {
        $root=$root."/";
    }


    if(!isset($_SESSION["u"]))
    {
        header("location:".$site."user");
        exit;
    }
    else{
        $u=$_SESSION["u"];
    }
    if(!isset($_POST["access"]))
    {
        echo "You cannot access this page";
        exit;

    }
    ?>



<!DOCTYPE html>
<html>
<head>


    <?php
    include($root."parts/resources.php");

    ?>



</head>
<body>


<?php
    // header also contents the <noscript> alert
    include($root."parts/header.php");

    ?>
<div class="wholepage">

<div class="page scatterList">


<?php



    if(isset($_FILES["profilePic"]))
            {
                $name=$_FILES["profilePic"]["name"];

                if($_FILES["profilePic"]["error"] !== UPLOAD_ERR_OK) {
                    die("Upload failed with error code ".$_FILES["profilePic"]["error"]);
                }

                if(!getimagesize($_FILES["profilePic"]["tmp_name"]))
                {
                    exit;
                }

                $path=$site."img/1/".$u.".jpg";

                move_uploaded_file($path, $_FILES["profilePic"]["tmp_name"]);
            }

                ?>







            </div> <!-- end of .page -->


            </div> <!-- wholepage -->
            <!-- FOOTER -->
                <?php
                include($root."parts/footer.php");
                ?>


            </body>
            </html>

答案 1 :(得分:1)

第48行:如果

开始
if (isset ($_FILES["profilePic"])) {

}结束标记不存在。

}标记放在move_uploaded_file第57行之后或您想要的位置。

像这样:

if (isset ($_FILES["profilePic"])) {
   $name = $_FILES["profilePic"]["name"];
   if ($_FILES["profilePic"]["error"] !== UPLOAD_ERR_OK) {
      die("Upload failed with error code " . $_FILES["profilePic"]["error"]);
   }

   if (!getimagesize($_FILES["profilePic"]["tmp_name"])) { exit;}

   $path = $site . "img/1/" . $u . ".jpg";
   move_uploaded_file($path, $_FILES["profilePic"]["tmp_name"]);
}

答案 2 :(得分:1)

你还没有关闭这个块

 if(isset($_FILES["profilePic"]))
 {

答案 3 :(得分:0)

如果陈述,你没有完成其中一个。

更改:

if(isset($_FILES["profilePic"]))
{
$name=$_FILES["profilePic"]["name"];

到:

if(isset($_FILES["profilePic"]))
{
$name=$_FILES["profilePic"]["name"];
}

答案 4 :(得分:0)

        <?php 
        if(isset($_FILES["profilePic"]))
        {
        $name=$_FILES["profilePic"]["name"];

        if($_FILES["profilePic"]["error"] !== UPLOAD_ERR_OK) {
        die("Upload failed with error code ".$_FILES["profilePic"]["error"]); 
        } 

        if(!getimagesize($_FILES["profilePic"]["tmp_name"]))
        {
         exit;
        }

        $path=$site."img/1/".$u.".jpg";

        move_uploaded_file($path, $_FILES["profilePic"]["tmp_name"]);
        }// this one

        ?> 

你永远不会关闭第一个if语句..