I have a pdf file which is located off my webpage’s root. I want to serve a file in ../cvs to my users using php.
Here is the code I have sofar:
header('Content-type: application/pdf');
$file = file_get_contents('/home/eamorr/sites/eios.com/www/cvs/'.$cv);
echo $file;
But when I call this php page, nothing gets printed! I’d like to simply serve the pdf file stored whose name is in $cv (e.g. $cv = 'xyz.pdf').
The ajax response to this PHP page returns the text of the pdf (gobbldy-gook!), but I want the file, not the gobbldy-gook!
I hope this makes sense.
Many thanks in advance,
Here’s the AJAX I’m using
$('#getCurrentCV').click(function(){
var params={
type: "POST",
url: "./ajax/getCV.php",
data: "",
success: function(msg){
//msg is gobbldy-gook!
},
error: function(){
}
};
var result=$.ajax(params).responseText;
});
I’d like the user to be prompted to download the file.
Don’t use XHR (Ajax), just link to a script like the one below. The HTTP headers the script outputs will instruct the browser to download the file, so the user will not navigate away from the current page.
Then, simplify your javascript: