Here's an example code for uploading video content in PHP:
HTML form for uploading the video:
python<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="video">
<input type="submit" value="Upload">
</form>
PHP code to handle the file upload:
php<?php
if(isset($_FILES['video'])) {
$errors = array();
$file_name = $_FILES['video']['name'];
$file_size = $_FILES['video']['size'];
$file_tmp = $_FILES['video']['tmp_name'];
$file_type = $_FILES['video']['type'];
$file_ext = strtolower(end(explode('.', $_FILES['video']['name'])));
$extensions = array("mp4", "avi", "mov", "wmv");
if (in_array($file_ext, $extensions) === false) {
$errors[] = "extension not allowed, please choose a MP4, AVI, MOV or WMV file.";
}
if ($file_size > 52428800) {
$errors[] = 'File size must be exactly 50 MB';
}
if (empty($errors) == true) {
move_uploaded_file($file_tmp, "videos/" . $file_name);
echo "Success";
} else {
print_r($errors);
}
}
?>
This code checks for the file type and size, and moves the uploaded file to the "videos" folder on the server if it passes validation. You can customize this code to fit your specific needs, such as adding additional validation checks or changing the file upload directory.
Comments
Post a Comment