@filiberto
To upload videos using JavaScript and PHP, you can follow these steps:
1 2 3 4 |
<form id="uploadForm" action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="videoFile" id="videoFile">
<button type="submit">Upload</button>
</form>
|
1 2 3 4 5 6 7 8 9 10 11 12 |
<?php
$uploadDir = 'videos/';
$uploadFile = $uploadDir . basename($_FILES['videoFile']['name']);
if (move_uploaded_file($_FILES['videoFile']['tmp_name'], $uploadFile)) {
echo "File is valid, and was successfully uploaded.
";
} else {
echo "Possible file upload attack!
";
}
?>
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
document.getElementById('uploadForm').addEventListener('submit', function(event) {
event.preventDefault();
var formData = new FormData(this);
var xhr = new XMLHttpRequest();
xhr.open('POST', 'upload.php', true);
xhr.onload = function() {
if (xhr.status >= 200 && xhr.status < 300) {
console.log(xhr.responseText);
}
};
xhr.send(formData);
});
|
By following these steps, you can create a simple video upload functionality using JavaScript and PHP.