How can PHP be used to create a file preview feature on a website?

To create a file preview feature on a website using PHP, you can use the `file_get_contents` function to read the file content and then display it in an appropriate format based on the file type. You can also use conditional statements to handle different file types such as images, PDFs, text files, etc.

<?php
$file_path = 'path/to/file'; // Specify the path to the file you want to preview

$file_extension = pathinfo($file_path, PATHINFO_EXTENSION);

if ($file_extension == 'jpg' || $file_extension == 'jpeg' || $file_extension == 'png' || $file_extension == 'gif') {
    echo '<img src="' . $file_path . '" />';
} elseif ($file_extension == 'pdf') {
    echo '<embed src="' . $file_path . '" type="application/pdf" width="100%" height="600px" />';
} else {
    echo nl2br(file_get_contents($file_path));
}
?>