PHP语句中的奇怪失败

时间:2015-06-30 14:52:42

标签: php if-statement

好的,所以这是我的代码。 (我以后会对它进行消毒。别担心。)

gallery_upload_new.php     

// Check if user wants to upload to existing or new album
if (isset($_POST['album'])) {
    if ($_POST['album'] == '') {
        $_POST['album'] = $_POST['new_album'];
    }
}

// Populate album dropdown menu
$albums = $database->query("SELECT DISTINCT(album) FROM images")->fetchAll(PDO::FETCH_COLUMN); 

// Load the 'upload new photo' interface if user's not uploading it already
if (!isset($_FILES['image_link']) || !isset($_POST['caption']) || $_POST['caption'] == '') {
    //var_dump($_FILES);
    //var_dump($_POST);
    include('views/gallery_upload_new.php');

// Otherwise store the image file, register it into database, and put the user back in the list of photos
} else {
    $new_image = new Image($_POST['caption'], $_POST['album']);
    $new_image->register($_FILES['image_link']['tmp_name'], $_FILES['image_link']['name']);
    header('location: gallery_management.php'); 
}
?>

views/gallery_upload_new.php

<!DOCTYPE html>
<html>
    <head>
        <title><?php echo $site_title; ?></title>
        <?php include('views/header.php'); //Just the global CSS and JavaScript ?>
    </head>
    <body>
        <?php include('views/nav_menu.php'); //Site navigation panel ?>
        <div id="content">
            <h1>Upload new photo</h1>
            <form enctype="multipart/form-data" action="gallery_upload_new.php" method="post">
                <p>
                    <strong>Upload to album: </strong>
                    <select name="album">
                        <?php
foreach($albums as $album_name) {
    echo "<option value='$album_name'>$album_name</option>";
}
                        ?>
                        <option id="selectNewAlbum" value="" selected>New album</option> <input type="text" placeholder="New album name" name="new_album" id="newAlbumName">
                    </select>
                </p>
                <p><strong>Photo caption</strong> <input type="text" name="caption"></p>
                <p><strong>Photo file: </strong><input type="file" required name="image_link"></p>
                <input type="submit" value="Unggah">
            </form>
        </div>
    </body>
</html>

这里有一个奇怪的部分:没有那两个var_dumpelse块不会执行。我确保$_POST$_FILES中的索引是正确的。然而,如果没有这些虚假转储,这件事就不会奏效。无论如何,只需加载views/gallery_upload_new.php

如果他们被评论出来,那就不重要了。他们只需要在那里。

我做错了什么?我在某处发生了语法错误吗?

0 个答案:

没有答案