Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. // Step1: this is the processing code
  2. $videoUploadData = new VideoUploadData(
  3. $_FILES["fileInput"],
  4. $_POST["titleInput"],
  5. $_POST["descriptionInput"],
  6. $_POST["privacyInput"],
  7. $_POST["categoryInput"],
  8. "REPLACE-THIS"
  9. );
  10.  
  11. $videoProcessor = new VideoProcessor($con);
  12. $wasSuccessful = $videoProcessor->upload($videoUploadData);
  13.  
  14. // Step2: this code creates the class VideoUploadData
  15.  
  16. class VideoUploadData {
  17.  
  18. public $videoDataArray, $title, $description, $privacy, $category, $uploadedBy;
  19.  
  20. public function __construct($videoDataArray, $title, $description, $privacy, $category, $uploadedBy) {
  21. $this->videoDataArray = $videoDataArray;
  22. $this->title = $title;
  23. $this->description = $description;
  24. $this->privacy = $privacy;
  25. $this->category = $category;
  26. $this->uploadedBy = $uploadedBy;
  27. }
  28.  
  29. }
  30.  
  31. // Step 3: this code creates the database upload
  32.  
  33. class VideoProcessor {
  34.  
  35. private $con;
  36.  
  37. public function __construct($con) {
  38. $this->con = $con;
  39. }
  40.  
  41. public function upload($videoUploadData) {
  42.  
  43. $targetDir = "uploads/videos/";
  44. $videoData = $videoUploadData->videoDataArray;
  45.  
  46. $tempFilePath = $targetDir . uniqid() . basename($videoData["name"]);
  47.  
  48. if(move_uploaded_file($videoData["tmp_name"], $tempFilePath)) {
  49.  
  50. $finalFilePath = $targetDir . uniqid() . ".mp4";
  51.  
  52. if(!$this->insertVideoData($videoUploadData, $finalFilePath)) {
  53. echo "Insert query failed";
  54. return false;
  55. }
  56.  
  57. }
  58. }
  59.  
  60. private function insertVideoData($uploadData, $filePath) {
  61.  
  62.  
  63. $query = $this->con->prepare("INSERT INTO `videos` (`uploadedBy`, `title`, `description`, `privacy`, `filePath`, `category`)
  64. VALUES (:uploadedBy, :title, :description, :privacy, :filePath, :category)");
  65.  
  66. $query->bindParam(":uploadedBy", $uploadData->uploadedBy);
  67. $query->bindParam(":title", $uploadData->title);
  68. $query->bindParam(":description", $uploadData->description);
  69. $query->bindParam(":privacy", $uploadData->privacy);
  70. $query->bindParam(":filePath", $filePath);
  71. $query->bindParam(":category", $uploadData->category);
  72.  
  73. return $query->execute();
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement