Talk nerdy to me
Talk nerdy to me

Reputation: 1085

Cant pass value as variable in this php script

Like the question says, I can't seem to pass a value in a variable in the following script. If I echo the variable, it exists as expected. If i copy and paste the echoed value into the code where $my_var is, it works. But it wont work with $my_var ?!?!?

Context- code requires another file to create a pdf, attaches it to an email and sends it, and then displays it in the browser. Have removed most of the code for brevity

$my_var = $_POST['quote_number'];
$filename = 'Quote_no' . $my_var . '.pdf';
$file = $_SERVER['DOCUMENT_ROOT'] . '/quotes/' . $filename ;
require('instant_quote.php');
function send_quote($my_var) {
     //my_function code
   };
send_quote($my_var);
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="' . $filename . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($file));
header('Accept-Ranges: bytes');
@readfile($file);

Upvotes: 0

Views: 81

Answers (2)

Talk nerdy to me
Talk nerdy to me

Reputation: 1085

Don't know why this worked, but it did...

header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="' . $file . '"');
header('Content-Length: ' . filesize($filename));
@readfile($filename);

Just removed the transfer encoding and accept-ranges from the headers, and it started accepting my variable as a value... go figure

Upvotes: 1

scrowler
scrowler

Reputation: 24406

The syntax highlighting in your example was helpful, you have incorrect matching quotes:

$filename = "Quote_no' . $my_var . '.pdf";

... should be:

$filename = 'Quote_no' . $my_var . '.pdf';

Upvotes: 1

Related Questions