0

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);
1
  • Tried taking that out, still doesn't work Commented Dec 12, 2013 at 4:35

2 Answers 2

1

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';
Sign up to request clarification or add additional context in comments.

10 Comments

Sorry, that was a mistake when I retyped the code, it's not in my actual code- edited to show
@Imaginate I can't see any difference in your question code, but have you tried var_dump($_POST) to make sure your value is actually there and doesn't contain anything you don't expect (e.g. whitespace on either end)?
Contents of var dump - array(11) { ["name"]=> string(0) "" ["company_name"]=> string(0) "" ["design_level"]=> string(5) "basic" ["address"]=> string(0) "" ["email"]=> string(0) "" ["content"]=> string(4) "none" ["type"]=> string(7) "Landing" ["size"]=> string(11) "single page" ["product_qty"]=> string(4) "< 30" ["action"]=> string(13) "instant_quote" ["quote_number"]=> string(5) "W1741" }
Looks fine, go through and var_dump every variable or function call in your script until you find something you weren't expecting
Use $_POST['quote_number'] instead of $my_var then :p
|
1

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

1 Comment

interesting... there must be some conflict between posted data and those headers being sent... +1 for working it out yourself

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.