dongquweng5152
dongquweng5152
2011-12-02 22:08

php文件上传错误

已采纳

I have been over and over this but I can not find why it is giving this error. Parse error: syntax error, unexpected $end in /home/valerie2/public_html/elinkswap/snorris/file.php on line 78. Maybe if there was more eyes on it maybe be able to find where I didnt do something right. Thanks for looking.

<?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. ?>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

3条回答

  • dongliuzi3410 dongliuzi3410 10年前

    Change you code to:

    <?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.";
          }
    
     ?>
    

    And please use the practice to indent your code, it will be a quick and easy way to correct these errors.

    点赞 评论 复制链接分享
  • dongtiandexue123456 dongtiandexue123456 10年前

    Line 78 is just before the ?>

    It is difficult to follow with so many nested IF staements, but it looks like you have failed to close 2 IFs (if submit and if name)

    点赞 评论 复制链接分享
  • douqi1931 douqi1931 10年前

    Change this:

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

    to....

    if ($size >1100000 && $size <1700000)
    {
        if($error > 0)
        {
        echo "Error!!!!!!".$error;
        }
    }
    
    点赞 评论 复制链接分享

相关推荐