How can PHP developers ensure the security of video uploads on a website?

To ensure the security of video uploads on a website, PHP developers can implement file type validation, check for file size limits, and store uploaded videos in a secure directory outside of the web root to prevent direct access.

// Validate file type
$allowed_types = array('mp4', 'avi', 'mov');
$uploaded_file_type = pathinfo($_FILES['video']['name'], PATHINFO_EXTENSION);

if (!in_array($uploaded_file_type, $allowed_types)) {
    die('Invalid file type. Only MP4, AVI, and MOV files are allowed.');
}

// Check file size
$max_file_size = 10000000; // 10MB
if ($_FILES['video']['size'] > $max_file_size) {
    die('File size exceeds limit. Maximum file size is 10MB.');
}

// Store uploaded video in a secure directory
$upload_dir = '/var/www/uploads/';
$upload_file = $upload_dir . basename($_FILES['video']['name']);

if (move_uploaded_file($_FILES['video']['tmp_name'], $upload_file)) {
    echo 'Video uploaded successfully.';
} else {
    echo 'Failed to upload video.';
}