图像上传错误


image uploading errors

所以我遇到了这个问题,我的错误在测试时没有显示出来,看它们是否在应该显示的时候显示。当我选择一个文件时,我的脚本应该只接受图像文件,并且不接受大于2MB的文件。我还没有写真正将图像上传到数据库和我创建的相册的部分,但无论如何,我应该会遇到一些错误,而不是只是传递任何信息。。我需要帮助!提前感谢!

以下是处理图像并最终上传的文件:

<?php
include 'init.php';
if(!logged_in()){
header('Location: index.php');
exit();
}
include 'template/header.php';
?>
<h3>Upload Image</h3>
<?php
if(isset($FILES['image'], $_POST['album_id'])){
$image_name = $_FILES['image']['name'];
$image_size = $_FILES['image']['size'];
$image_temp = $_FILES['image']['tmp_name'];
$allowed_ext = array('jpg', 'jpeg', 'png', 'gif');
$image_ext = strtolower(end(explode('.', $image_name)));
$album_id = $_POST['album_id'];
$errors = array();
if (empty($image_name) || empty($album_id)){
    $errors[] = 'Something is missing';
} else {
    if(in_array($image_ext, $allowed_ext) === false){
        $errors[] = 'File type not allowed';
    }
    if($image_size > 2097152){
        $errors[] = 'Maximum file size is 2MB'; 
    }
    if(album_check($album_id) === false){
        $errors[] = 'Couldn''t upload to that album';
    }
}
if(!empty($errors)){
    foreach ($errors as $error){
        echo $error, '<br />';
    }
} else {
    // upload image
}
}
$albums = get_albums();
if(empty($albums)){
echo '<p>You don''t have any albums. <a href="create_album.php">Create an album</a></p>';
} else {
?>
<form action="" method="post" enctype="multipart/form-data">
<p>Choose a file:<br /><input type="file" name="image" /></p>
<p>
Choose an album:<br />
<select name="album_id">
    <?php 
    foreach ($albums as $album){
        echo '<option value="', $album['id'], '">', $album['name'], '</option>';
    }
    ?>
</select>
</p>
<p><input type="submit" value="Upload" /></p>
</form>
<?php
}
include 'template/footer.php';
?>

我想我的问题是我的错误,但我不确定,再次感谢任何帮助!谢谢-TechGuy24

更改if(isset($FILES['image'], $_POST['album_id'])){

if(isset($_FILES['image'], $_POST['album_id'])){