0

I'm trying to display a file in the browser. My code works fine with .txt,.jpeg and .pdf. But when the file type is .docx, the browser will download my php file. My question is why is my php file downloaded instead of the actual .docx file, and how to solve this problem. Thank you!

<?php
session_start();

$file_name = $_POST["view"];
$finfo = new finfo(FILEINFO_MIME_TYPE);
$mime = $finfo->file($file_name);

header("Content-Type: " . $mime);
readfile($file_name);
?>
JYLock
  • 1
  • 1
  • 1

0 Answers0