How to implemen...LOGIN

How to implement the function of adding content

Now we will implement the function of adding web content. Content addition mainly involves adding titles, content, videos, categories, etc. to the database, and then displaying them on the main page.

First, we need to add a jump link in list.php , jump to add.php:

37.png

In video Create an upload file under the document to store the locally uploaded video source files.

You need to introduce an upload class here: uploads.class.php class. This class is placed in the admin folder and is used to upload video files to the database. Call this class in add.php.

uploads.class.zip

<?php
 include_once("uploads.class.php");
  $title = isset($_POST['title'])?$_POST['title']:"";
  $name = isset($_POST['name'])?$_POST['name']:"";
  $video = isset($_POST['video'])?$_POST['video']:"";
   // 调用uploads类
  $upobj=new upload();
  $ret=$upobj->upload_file();
  if($ret['status']>0)
  {
    $video=$ret['msg'];
  }else{
    $video='';
    die($ret['msg']);
  }
?>

Then it is determined that only when the title, content and video are added at the same time can it be uploaded to the database and jump to the main display page .

<?php
if($title && $name && $video)
{
        //注意video 的本地路径
    $video = str_replace("../","/",$video);
    $sql = "insert into list(title,name,time,video) values('".$title."','".$name."','".time()."','".$video."')";
    $rel = mysqli_query($link,$sql);
    if($rel)
    {
        echo "<script type='text/javascript'>alert('添加成功!');window.location='list.php'</script>";
    }
}else{
  echo "<script type='text/javascript'>alert('添加失败,请重新添加');</script>";
}
?>


Next Section
<?php header("content-type:text/html;charset=utf-8"); include("config.php"); if($_POST){ include_once("uploads.class.php"); $title = isset($_POST['title'])?$_POST['title']:""; $name = isset($_POST['name'])?$_POST['name']:""; $video = isset($_POST['video'])?$_POST['video']:""; // 调用uploads类 $upobj=new upload(); $ret=$upobj->upload_file(); if($ret['status']>0) { $video=$ret['msg']; }else{ $video=''; die($ret['msg']); } if($title && $name && $video) { $video = str_replace("../","/",$video); $sql = "insert into list(title,name,time,video) values('".$title."','".$name."','".time()."','".$video."')"; $rel = mysqli_query($link,$sql); if($rel) { echo "<script type='text/javascript'>alert('添加成功!');window.location='list.php'</script>"; } }else{ echo "<script type='text/javascript'>alert('添加失败,请重新添加');</script>"; } } ?>
submitReset Code
ChapterCourseware