Php 图像上传到博客系统问题

Php 图像上传到博客系统问题,php,Php,我的一个php文件有问题,它没有上传它添加到数据库中的图像,ok,但../images文件夹中没有图像?我也得到了以下错误 [2019年9月28日14:29:36欧洲/伦敦]PHP通知:未定义变量: 在第176行签入/home/blog/admin/add-post.php 管理员-添加帖子 tinymce.init({ 选择器:“文本区域”, 插件:[ “advlist autolink列出链接图像charmap打印预览锚”, “searchreplace visualblocks代码全屏显

我的一个php文件有问题,它没有上传它添加到数据库中的图像,ok,但../images文件夹中没有图像?我也得到了以下错误

[2019年9月28日14:29:36欧洲/伦敦]PHP通知:未定义变量: 在第176行签入/home/blog/admin/add-post.php


管理员-添加帖子
tinymce.init({
选择器:“文本区域”,
插件:[
“advlist autolink列出链接图像charmap打印预览锚”,
“searchreplace visualblocks代码全屏显示”,
“insertdatetime媒体表上下文菜单粘贴”
],
工具栏:“插入文件撤消重做|样式选择|粗体斜体|对齐左对齐中心对齐右对齐对齐对齐|粗体numlist outdent缩进|链接图像”
});

添加帖子 标题

内容

类别

我曾尝试用谷歌搜索错误,但无法解决我已检查重新更改的代码,但仍然没有图像上载数据库正在显示图像,但没有显示文件夹


此外,像176这样的版本仍然存在问题,但代码对我来说很正确。有人能告诉我出了什么问题吗?

现在修复了图像上传的问题。但仍然存在类似176
code
echo“$row2['catTitle']”的问题。“
”;}>
code
只需在循环外部为
$checked
设置一个初始值,你能告诉我关于我把这个im放入php学习的什么地方吗你可以把
$checked='',只要它出现在
之前($row2=$stmt2->fetch()){
您应该可以,这样至少可以定义它
    <?php //include config
require_once('../includes/config.php');

//if not logged in redirect to login page
if(!$user->is_logged_in()){ header('Location: login.php'); }
?>
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Admin - Add Post</title>
  <link rel="stylesheet" href="../style/normalize.css">
  <link rel="stylesheet" href="../style/main.css">
  <script src="//tinymce.cachefly.net/4.0/tinymce.min.js"></script>
  <script>
          tinymce.init({
              selector: "textarea",
              plugins: [
                  "advlist autolink lists link image charmap print preview anchor",
                  "searchreplace visualblocks code fullscreen",
                  "insertdatetime media table contextmenu paste"
              ],
              toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"
          });
  </script>
</head>
<body>

<div id="wrapper">

    <?php include('menu.php');?>
    <p><a href="./">Blog Admin Index</a></p>

    <h2>Add Post</h2>

    <?php

    //if form has been submitted process it
    if(isset($_POST['submit'])){

        // location where initial upload will be moved to
        $target = "images/" . $_FILES['postImage']['name'];
        $path = '../'.$target;

        //collect form data
        extract($_POST);

        //very basic validation
        if($postTitle ==''){
            $error[] = 'Please enter the title.';
        }

        if($postDesc ==''){
            $error[] = 'Please enter the description.';
        }

        if($postCont ==''){
            $error[] = 'Please enter the content.';
        }

        if(isset($_FILES['postImage'])){

            // find thevtype of image
            switch ($_FILES["postImage"]["type"]) {
            case $_FILES["postImage"]["type"] == "image/gif":
                move_uploaded_file($_FILES["postImage"]["tmp_name"], $path);
                break;
            case $_FILES["postImage"]["type"] == "image/jpeg":
                   move_uploaded_file($_FILES["postImage"]["tmp_name"], $path);
                break;
            case $_FILES["postImage"]["type"] == "image/pjpeg":
                   move_uploaded_file($_FILES["postImage"]["tmp_name"], $path);
                break;
            case $_FILES["postImage"]["type"] == "image/png":
                move_uploaded_file($_FILES["postImage"]["tmp_name"], $path);
                break;
            case $_FILES["postImage"]["type"] == "image/x-png":
                move_uploaded_file($_FILES["postImage"]["tmp_name"], $path);
                break;

            default:
                $error[] = 'Wrong image type selected. Only JPG, PNG or GIF accepted!.';
            }

        }

        if(!isset($error)){

            try {

                $postSlug = slug($postTitle);

                //insert into database
                $stmt = $db->prepare('INSERT INTO blog_posts_seo (postTitle,postSlug,postDesc,postCont,postDate) VALUES (:postTitle, :postSlug, :postDesc, :postCont, :postDate)') ;
                $stmt->execute(array(
                    ':postTitle' => $postTitle,
                    ':postSlug' => $postSlug,
                    ':postDesc' => $postDesc,
                    ':postCont' => $postCont,
                    ':postDate' => date('Y-m-d H:i:s'),
                ));
                $postID = $db->lastInsertId();

                if(isset($_FILES['postImage'])){

                    $stmt = $db->prepare('UPDATE blog_posts_seo SET postImage = :image WHERE postID = :postID') ;
                    $stmt->execute(array(
                        ':postID' => $postID,
                        ':image' => $target
                    ));
                }

                //add categories
                if(is_array($catID)){
                    foreach($_POST['catID'] as $catID){
                        $stmt = $db->prepare('INSERT INTO blog_post_cats (postID,catID)VALUES(:postID,:catID)');
                        $stmt->execute(array(
                            ':postID' => $postID,
                            ':catID' => $catID
                        ));
                    }
                }

                //redirect to index page
                header('Location: index.php?action=added');
                exit;

            } catch(PDOException $e) {
                echo $e->getMessage();
            }

        }

    }

    //check for any errors
    if(isset($error)){
        foreach($error as $error){
            echo '<p class="error">'.$error.'</p>';
        }
    }
    ?>

    <form action='' method='post' enctype="multipart/form-data">

        <p><label>Title</label><br />
        <input type='text' name='postTitle' value='<?php if(isset($error)){ echo $_POST['postTitle'];}?>'></p>

        <p><label>Image</label><br />
        <input type='file' name='postImage'></p>

        <p><label>Description</label><br />
        <textarea name='postDesc' cols='60' rows='10'><?php if(isset($error)){ echo $_POST['postDesc'];}?></textarea></p>

        <p><label>Content</label><br />
        <textarea name='postCont' cols='60' rows='10'><?php if(isset($error)){ echo $_POST['postCont'];}?></textarea></p>


        <fieldset>
            <legend>Categories</legend>

            <?php   

            $stmt2 = $db->query('SELECT catID, catTitle FROM blog_cats ORDER BY catTitle');
            while($row2 = $stmt2->fetch()){

                if(isset($_POST['catID'])){

                    if(in_array($row2['catID'], $_POST['catID'])){
                       $checked="checked='checked'";
                    }else{
                       $checked = null;
                    }
                }

                echo "<input type='checkbox' name='catID[]' value='".$row2['catID']."' $checked> ".$row2['catTitle']."<br />";
            }

            ?>

        </fieldset>

        <p><input type='submit' name='submit' value='Submit'></p>

    </form>

</div>