我找不到我的PHP错误,它给了我T_ELSE

时间:2018-12-13 02:07:26

标签: php performance gallery

它给了我这个错误,有人可以帮我吗? (!)解析错误:语法错误,第59行的C:\ wamp64 \ www \ photogallery \ includes \ gallery-upload.inc.php中出现意外的'else'(T_ELSE)

她是我的代码,希望您能对我有所帮助。我找不到我的错误。 有人可以回答我的考试吗,大约需要2个小时。     

$newFileName = $_POST['filename'];
if(empty(empty($newFileName))) {
    $newFileName = "gallery";
} else {
    $newFileName = strtolower(str_replace(" ", "-", $newFileName));
}
$imageTitle = $_POST['filetitle'];
$imageDesc = $_POST[''];

$file = $_FILES['file'];

$fileName = $file["name"];
$fileType = $file["type"];
$fileTempName = $file["tmp_name"];
$fileError = $file["error"];
$fileSize = $file["size"];

$fileExt = explode($fileName);
$fileActualExt = strtolower(end($fileExt));

$allowed = array("jpg", "jpeg", "png");

if (in_array($fileActualExt, $allowed)) {
    if ($fileError === 0) {
        if(fileSize < 2000000) {
        $imageFullName = $newFileName ."." . uniqid("", true) ."." . $fileActualExt;
        $fileDestination = "../img/gallery/" . $imageFullName;

        include_once "dbh.inc.php";
        if (empty($imageTitle) || empty($imageDesc)) {
            header("Location: ../gallery.php?upload=empty");
            exit();
        } else {
            $sql = "SELECT * FROM gallery";
            $stmt = mysqli_stmt_init($conn);
            if (!mysqli_stmt_prepare($stmt, $sql)) {
                echo "SQL statement failed!";
            } else {
                mysqli_stmt_execute($stmt);
                $result = mysqli_stmt_get_result($stmt);
                $rowCount = mysqli_num_rows($result);
                $setImageOrder = $rowCount + 1;

                $sql = "INSERT INTO gallery (titleGallery, descGallery, imgFullNameGallery, orderGallery) VALUES (?, ?, ?, ?);";
                if (!mysqli_stmt_prepare($stmt, $sql)) {
                echo "SQL statement failed!";
            } else {
                mysqli_stmt_bind_param($stmt, "ssss", $imageTitle, $imageDesc, $imageFullName, $setImageOrder);
                mysqli_stmt_execute($stmt);

                move_uploaded_file($fileTempName, $fileDestination);

                header("Location: ../gallery.php?upload=succes");
            }
        }
    } else {
        echo "File size is to big";
        exit();
    } else {
        echo "You had an error!";
        exit();
    } else {
        echo "You need to upload a proper file type!";
        exit();
    }

} ?>

2 个答案:

答案 0 :(得分:0)

此错误意味着在ELSE语句之前紧挨着缺少一些内容。它说unexpected 'else',这意味着它在else之前还有其他期望。

代码很可能在前一行缺少分号或右括号。但是,如果您在gallery-upload.inc.php文件的第59行附近发布代码,我们可以为您提供更明确的答案。您从哪里获得此文件的?

答案 1 :(得分:0)

我认为您不能使用多个其他导致上述错误的信息。
错误代码:

if (condition) {
    echo 'test';
} else {
    echo "File size is to big";
    exit();
} else {
    echo "You had an error!";
    exit();
} else {
    echo "You need to upload a proper file type!";
    exit();
}  

在条件中使用else-if。

if (condition) {
   //something
} else if (condition) {
   //something
} else {
   //something
}

希望这会有所帮助! Tq