I'm unsure how to approach solving this problem. I have a link that when clicked downloads the file to the users machine. The file is a pdf. If I copy and paste the file onto the desktop and then open that copy, it works perfectly fine. Yet when the user downloads and tries to open, I get this:
Here is the code:(fyi: i have validation on the filename before this..)
$file_name = $dat->filename; //'file.avi';
$file_url = $dat->path . $dat->url . $filename;
header('Content-Type:'. $dat->type);
header("Content-disposition: attachment; filename=\"" . $file_name . "\"");
header("filename=\"" . $file_name . "\"");
readfile($file_url);
exit;
I have tried multiple headers but nothing seems to work. What am I doing wrong with this encoding? Seems to me that the file is valid and should be a simple copy to the users machine just like the copy I made locally worked just fine.
Update
I opened the file as per Marcin's suggestion, in Sublime. This is what I get.. no body?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<link rel="stylesheet" type="text/css" href="/assets/jQuery/jquery-ui-1.12.1/jquery-ui.min.css">
<script src="/assets/jQuery/jquery-3.2.1.min.js"></script>
<script src="/assets/jQuery/jquery-ui-1.12.1/jquery-ui.min.js"></script>
<script src="/assets/pdfObject/pdfObject.js"></script>
<style>
body{
overflow: hidden;
}
.pdfobject-container {
height: 99vh;
overflow: hidden;
}
</style>
<title></title>
</head>
<body>