my_course_update.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. require_once "../config.php";
  3. require_once "../public/_pdo.php";
  4. require_once '../public/function.php';
  5. $respond=array("status"=>0,"message"=>"");
  6. //处理文件上传
  7. if(isset($_FILES["cover"])){
  8. if ((($_FILES["cover"]["type"] == "image/gif")
  9. || ($_FILES["cover"]["type"] == "image/jpeg")
  10. || ($_FILES["cover"]["type"] == "image/png"))
  11. && ($_FILES["cover"]["size"] < 2000000))
  12. {
  13. if ($_FILES["cover"]["error"] > 0)
  14. {
  15. $respond['status']=1;
  16. $respond['message']=$_FILES["cover"]["error"];
  17. }
  18. else
  19. {
  20. move_uploaded_file($_FILES["cover"]["tmp_name"],
  21. _DIR_IMAGES_COURSE_."/" . $_POST["course"].".jpg");
  22. }
  23. }
  24. else
  25. {
  26. echo "Invalid file";
  27. $respond['status']=1;
  28. $respond['message']="Invalid file";
  29. }
  30. }
  31. //处理文件上传结束
  32. PDO_Connect(""._FILE_DB_COURSE_);
  33. $query="UPDATE course SET title = ? , subtitle = ? , summary = ? , teacher = ? , tag = ? , lang = ? , attachment = ? , status = ? , receive_time = ? , modify_time = ? where id = ? ";
  34. $sth = $PDO->prepare($query);
  35. $sth->execute(array( $_POST["title"] , $_POST["subtitle"] , $_POST["summary"] , $_POST["teacher"] , $_POST["tag"] , $_POST["lang"] , $_POST["attachment"] ,$_POST["status"] , mTime() , mTime() , $_POST["course"]));
  36. if (!$sth || ($sth && $sth->errorCode() != 0)) {
  37. $error = PDO_ErrorInfo();
  38. $respond['status']=1;
  39. $respond['message']=$error[2];
  40. }
  41. else{
  42. $respond['status']=0;
  43. $respond['message']="成功";
  44. }
  45. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  46. ?>