Reputation: 77
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.
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>
Upvotes: 0
Views: 50
Reputation: 75645
I'd open the file in i.e. text editor or binary editor and see what's inside. My blind guess you is that you will find there some sort of i.e. PHP notice/error message or something polluting the data other way.
Upvotes: 1