1

I am trying to pass a variable thorugh HTML anchor tag thorugh form. On form submit the value in anchor is passed to my .php file . Here in php file I have stored the passed value in a variable and now I want to use this value in header.

index.html
In below HTML I am passing variable "text1.pdf" to form.php

<a href="#" title="Download" target="_blank" onclick="document.myform.formVar.value='text1.pdf';document.myform.submit(); return false">Download</a>

<form method=post name="myform" action="form.php" style="display:none;">
<input type="hidden" name="formVar" value="">
<input type="submit" value="Send form!">

Form.php

$fileName = $_POST['formVar'];  
// Defining file URL
$fileURL="pdf/";
$fileURL .=$fileName;
header( "Location: ".$fileURL);

Here I am trying to form a URL using passed variable. And trying to put that variable in header. But I am not able to reach to that specific file. When I submit form on form.php it gets redirected to "pdf/" url instead of "pdf/text.pdf" .

1
  • This isn't very secure. What's to stop somebody from modifying the POST data and downloading other files? Commented Sep 21, 2011 at 5:25

1 Answer 1

1

In Form.php:

$fileURL .=$fileURL; 

should be

$fileURL .=$fileName; 
Sign up to request clarification or add additional context in comments.

Comments

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.