php文件上传错误

时间:2011-12-02 22:08:24

标签: php

我一遍又一遍,但我找不到为什么会出现这个错误。解析错误:语法错误,第78行/home/valerie2/public_html/elinkswap/snorris/file.php中的意外$结束。也许如果有更多的眼睛,也许能够找到我没有做对的地方。谢谢你的期待。

<?php

session_start();


include "connect.php";

if ($_POST["submit"])
{



    //Coding
    if($_SESSION["name"])

    {



    //variables

    $name = $_FILES["file"]["name"];
    $type = $_FILES["file"]["type"];
    $size = $_FILES["file"]["size"];
    $tmp_name = $_FILES["file"]["tmp_name"];
    $error = $_FILES["file"]["error"];

    if ($type =="image/jpeg" || $type =="image/gif")
    {

        if ($size >1100000 && $size <1700000)
        {

            if($error > 0)
            {

            echo "Error!!!!!!".$error;

    }
    else

    {

    if(file_exists("upload/".$name))

    {
    echo $name." already exists.";
    }

else
    {
    $location ="upload/".$name;
    move_uploaded_file($tmp_name,$location);
    $user = $_SESSION["name"];


    $sqlcode = mysql_query("INSERT INTO imageupload (id,user,location) VALUES ('','$user','$location')");


    echo "<a href='$location'>Click here to view your image.</a>";
    }

  }


}
else
    {

    echo "Please check the size of your File..";
    }
}
else
{
    echo "Invalid file format.";
}
  1. &GT;

3 个答案:

答案 0 :(得分:2)

第78行就在?>

之前

很难跟随如此多的嵌套IF标记,但看起来你没有关闭2个IF(如果提交,如果名称)

答案 1 :(得分:1)

将您的代码更改为:

<?php
      session_start();
      include "connect.php";
      if ( $_POST[ "submit" ] ) {
             if ( $_SESSION[ "name" ] ) {
                    $name = $_FILES[ "file" ][ "name" ];
                    $type = $_FILES[ "file" ][ "type" ];
                    $size = $_FILES[ "file" ][ "size" ];
                    $tmp_name = $_FILES[ "file" ][ "tmp_name" ];
                    $error = $_FILES[ "file" ][ "error" ];
                    if ( $type == "image/jpeg" || $type == "image/gif" ) {
                           if ( $size > 1100000 && $size < 1700000 ) {
                                  if ( $error > 0 ) {
                                         echo "Error!!!!!!" . $error;
                                  } else {
                                         if ( file_exists( "upload/" . $name ) ) {
                                                echo $name . " already exists.";
                                         }
                                  }
                           } else {
                                  $location = "upload/" . $name;
                                  move_uploaded_file( $tmp_name , $location );
                                  $user = $_SESSION[ "name" ];
                                  $sqlcode = mysql_query( "INSERT INTO imageupload (id,user,location) VALUES ('','$user','$location')" );
                                  echo "<a href='$location'>Click here to view your image.</a>";
                           }
                    }
             } else {

                    echo "Please check the size of your File..";
             }
      } else {
             echo "Invalid file format.";
      }

 ?>

请使用练习缩进代码,这将是一种快速简便的方法来纠正这些错误。

答案 2 :(得分:1)

改变这个:

if ($size >1100000 && $size <1700000)
{
    if($error > 0)
    {
    echo "Error!!!!!!".$error;
    }

到....

if ($size >1100000 && $size <1700000)
{
    if($error > 0)
    {
    echo "Error!!!!!!".$error;
    }
}