Я создал форму, в которой есть текстовые поля и видеомагнитофон. Текстовые поля загружаются в базу данных без проблем, и видео начинается и останавливается запись. Проблема в том, что видео не загружается на сервер, а имя видеофайла не вставляется в базу данных. Любая помощь будет оценена. Вот код формы:
<?php require_once('../Connections/sc_public_comment.php'); ?>
<?php require_once('../webassist/mysqli/rsobj.php'); ?>
<?php require_once('../webassist/mysqli/queryobj.php'); ?>
<?php
if (isset($_POST["submit"]) || isset($_POST["submit_x"])) {
$InsertQuery = new WA_MySQLi_Query($sc_public_comment);
$InsertQuery->Action = "insert";
$InsertQuery->Table = "public_comment_requests";
$InsertQuery->bindColumn("requestor_name", "s", "".((isset($_POST["requestor_name"]))?$_POST["requestor_name"]:"") ."", "WA_DEFAULT");
$InsertQuery->bindColumn("requestor_email", "s", "".((isset($_POST["requestor_email"]))?$_POST["requestor_email"]:"") ."", "WA_DEFAULT");
$InsertQuery->bindColumn("phone", "s", "".((isset($_POST["phone"]))?$_POST["phone"]:"") ."", "WA_DEFAULT");
$InsertQuery->bindColumn("address", "s", "".((isset($_POST["address"]))?$_POST["address"]:"") ."", "WA_DEFAULT");
$InsertQuery->bindColumn("address2", "s", "".((isset($_POST["address2"]))?$_POST["address2"]:"") ."", "WA_DEFAULT");
$InsertQuery->bindColumn("city", "s", "".((isset($_POST["city"]))?$_POST["city"]:"") ."", "WA_DEFAULT");
$InsertQuery->bindColumn("meeting", "s", "".((isset($_POST["meeting"]))?$_POST["meeting"]:"") ."", "WA_DEFAULT");
$InsertQuery->bindColumn("motion", "s", "".((isset($_POST["motion"]))?$_POST["motion"]:"") ."", "WA_DEFAULT");
$InsertQuery->bindColumn("video", "s", "".((isset($_POST["video"]))?$_POST["video"]:"") ."", "WA_DEFAULT");
$InsertQuery->saveInSession("requestor_name");
$InsertQuery->execute();
$InsertGoTo = "upload-video.php";
if (function_exists("rel2abs")) $InsertGoTo = $InsertGoTo?rel2abs($InsertGoTo,dirname(__FILE__)):"";
$InsertQuery->redirect($InsertGoTo);
}
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>CPS School Committee: Sign Up for Virtual Public Comment</title>
<link href="css/video-js.min.css" rel="stylesheet">
<link href="css/videojs.record.css" rel="stylesheet">
<link href="assets/examples.css" rel="stylesheet">
<script src="js/video.min.js"></script>
<script src="js/RecordRTC.js"></script>
<script src="js/adapter.js"></script>
<script src="js/videojs.record.js"></script>
<script src="browser-workarounds.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<style>
/* change player background color */
#myVideo {
background-color: #9ab87a;
}
</style>
</head>
<body>
<div class="container w-75 mt-3">
<h1><font color="#006272"><img class="img-fluid" src="images/cps_logo_color.png" width="242" height="69" align="right" hspace="3px" vspace="3px" alt="CPS Logo"/>Sign Up for Virtual Public Comment</font></h1>
<p>To sign up to for public comment during a School Committee meeting, please fill out the following information. You must sign up by 5:30PM on the day of the meeting in question in order to participate in public comment.</p><hr style="color:#00A499;">
<h3><font color="#00A499">STEP 1: Please fill out the following:</font></h3>
<form action="" method="post"><div class="form-row">
<div class="form-group col-md-6">
<label for="requestor_name">Name</label>
<input type="text" class="form-control" name="requestor_name" id="requestor_name" placeholder="Full Name" required>
</div>
<div class="form-group col-md-6">
<label for="requestor_email">Email</label>
<input type="email" name="requestor_email" class="form-control" id="requestor_email" placeholder="Email" required>
</div>
<div class="form-group col-md-6">
<label for="phone">Phone</label>
<input type="text" class="form-control" name="phone" id="Phone" placeholder="Phone" required>
</div>
</div>
<div class="form-group">
<label for="address">Address</label>
<input type="text" class="form-control" id="address" name="address" placeholder="1234 Main St" required>
</div>
<div class="form-row">
<div class="form-group col-md-4">
<label for="address2">Address 2</label>
<input type="text" class="form-control" id="address2" name="address2" placeholder="Apartment, studio, or floor">
</div>
<div class="form-group col-md-4">
<label for="city">City</label>
<input type="text" class="form-control" id="city" name="city" required>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label for="meeting">Select a Meeting:</label>
<select name="meeting" id="meeting" required>
<option selected="selected">Select One</option>
<option value-"2020_04_07">Regular School Committee Meeting: April 7, 2020</option>
</select>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label for="motion">Which motion do you want to speak in reference to:</label><br>
<textarea name="motion" cols="40" rows="3" required></textarea>
</div>
</div><hr style="color:#00A499;">
<h3><font color="#00A499">STEP 2: Record Your Video</font></h3>
Click on Start Recording and then record your message. Once you are done, click on Stop Recording. Your video will then be previewed on the screen. After you are satisifed with the video, click on Submit Request.<br><br>
<!-- 1. Include action buttons play/stop -->
<button id="btn-start-recording" class="btn btn-warning">Start Recording</button>
<button id="btn-stop-recording" disabled="disabled" class="btn btn-danger">Stop Recording</button>
<!--
2. Include a video element that will display the current video stream
and as well to show the recorded video at the end.
-->
<hr>
<video id="my-preview" controls autoplay></video>
<!-- 4. Initialize and prepare the video recorder logic -->
<script>
// Store a reference of the preview video element and a global reference to the recorder instance
var video = document.getElementById('my-preview');
var recorder;
// When the user clicks on start video recording
document.getElementById('btn-start-recording').addEventListener("click", function(){
// Disable start recording button
this.disabled = true;
// Request access to the media devices
navigator.mediaDevices.getUserMedia({
audio: true,
video: true
}).then(function(stream) {
// Display a live preview on the video element of the page
setSrcObject(stream, video);
// Start to display the preview on the video element
// and mute the video to disable the echo issue !
video.play();
video.muted = true;
// Initialize the recorder
recorder = new RecordRTCPromisesHandler(stream, {
mimeType: 'video/mpeg',
bitsPerSecond: 128000
});
// Start recording the video
recorder.startRecording().then(function() {
console.info('Recording video ...');
}).catch(function(error) {
console.error('Cannot start video recording: ', error);
});
// release stream on stopRecording
recorder.stream = stream;
// Enable stop recording button
document.getElementById('btn-stop-recording').disabled = false;
}).catch(function(error) {
console.error("Cannot access media devices: ", error);
});
}, false);
// When the user clicks on Stop video recording
document.getElementById('btn-stop-recording').addEventListener("click", function(){
this.disabled = true;
recorder.stopRecording().then(function() {
console.info('stopRecording success');
// Retrieve recorded video as blob and display in the preview element
var videoBlob = recorder.getBlob();
video.src = URL.createObjectURL(videoBlob);
video.play();
// Unmute video on preview
video.muted = false;
// Stop the device streaming
recorder.stream.stop();
// Enable record button again !
document.getElementById('btn-start-recording').disabled = false;
}).catch(function(error) {
console.error('stopRecording failure', error);
});
}, false);
// user completed recording and stream is available
player.on('finishRecord', function() {
// the blob object contains the recorded data that
// can be downloaded by the user, stored on server etc.
console.log('finished recording: ', player.recordedData);
var formData = new FormData();
formData.append('audiovideo', player.recordedData.video);
// Execute the ajax request, in this case we have a very simple PHP script
// that accepts and save the uploaded "video" file
xhr('upload-video.php', formData, function (fName) {
console.log("Video succesfully uploaded !");
});
// Helper function to send
function xhr(url, data, callback) {
var request = new XMLHttpRequest();
request.onreadystatechange = function () {
if (request.readyState == 4 && request.status == 200) {
callback(location.href + request.responseText);
}
};
request.open('POST', url);
request.send(data);
}
});
</script><br><br>
<button type="submit" name="submit" id="submit" class="btn-info btn-lg">Submit Request</button><br><br></form>
</div>
</body>
</html>
Это видео для загрузки. php file:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
?>
<?php
if(isset($_FILES["audiovideo"])){ // save audio and video
$fileName = $_SESSION['requestor_name'];
$uploadDirectory = "upload_files/". $fileName."_". date("Y-m-d-H-i-s-").time()."mpeg";
if (!move_uploaded_file($_FILES["audiovideo"]["tmp_name"], $uploadDirectory)) {
echo("Couldn't upload video !");
}
else{
echo("File Moved");
}
}
elseif(isset($_FILES["video"])){ // save video only
$fileName = $_SESSION['requestor_name'];
$uploadDirectory = "upload_files/". $fileName."_". date("Y-m-d-H-i-s-").time()."mpeg";
if (!move_uploaded_file($_FILES["video"]["tmp_name"], $uploadDirectory)) {
echo("Couldn't upload video !");
}
else{
echo("File Moved");
}
}
elseif(isset($_FILES["stream"])){ // save streamming
$fileName = $_SESSION['requestor_name'];
$uploadDirectory = "upload_files/". $fileName."_". date("Y-m-d-H-i-s-").time()."mpeg";
if (!move_uploaded_file($_FILES["stream"]["tmp_name"], $uploadDirectory)) {
echo("Couldn't upload video !");
}
else{
echo("Success");
}
}
else{
echo "No file uploaded";
}
header("Location: confirm.php");
?>