How input a URL using form and redirect the URL as per the values of form Input

Hai Friends,
I am new to PHP Help, I am here to as you a doubt, How I want create a form using php/html that submit two values (Say, Name and Age), and a submit button, I will keep some pdf documents with their name as ‘Name_age.pdf’ so on submitting the form if the same name and age file is available the user can download the pdf other wise it has to show sorry try again, can anyone help on this.
Hope you understood the idea.

Welcome to the site, Nafihudheen !

First, have you coded any of this yet? Inputting data is easy to do using forms.
Saving the data is easy, too. Creating a PDF would require a lot of work if you have not done this before. It can be done with libraries which make it easy. Saving a file of any type using a name and age is also easy. This would not be a very secure system as anyone could type in someone else name and age and retrieve their data.

On your example, to create a file named using variables, you use a form to retrieve the name and age. Let’s say they are in variables $name and $age. And, you have created the PDF file and it is called $pdf.
To save it, you would simply write out the file using a command like this:
$pdf_filename = $name . “_” . $age . “.pdf”; // Create filename using name, age of filetype .pdf
file_put_contents($pdf_filename, $pdf); // Save to disk…
Of course, you might need to add in folders to the filename to save it where you want it to go and this is only a brief simple example. If you have code to show us perhaps we can help you sort it out.

PS: Is this for a class project? If so, have you read any of your manuals yet?

Hai ErbueAlex,

Thank you for your replay, Actually my project is a small project. I saved some pdf files in a folder, the file name I put ‘Name_age.pdf’ (the information is not confidential, so anyone who is having the name and age can access the file no problem).
If any one is inputting the Name and Age on my form it has to redirect to that file to download, if the file is available otherwise if has to show an error message.

I done something like as follows


$file_name = $name. ‘_’ . $age. ‘.pdf’;
header(‘Location:’ . $file_name);
header(‘Location: FailedLogin.php’);

Here now my problem is solved but I want to open the files which is going to download in new tab window, How’s that possible I think the header() function cannot redirect to another tab.

Could you please help on that…

Thank you…

thanks for the explanation, Nafihudheen. I think you can do this using the windows-open function.
Try this and let us know if it works for you.

echo "<script>'" . $file_name . ")</script>";

But, I have seen notes that you need to actually use your full website address to make it display. If you need to do that, you would need to do it this way, changing the web info for your server name of course!

echo "<script>'" . $file_name . ")</script>";

Not tested, that is your job… Let us know… ErnieAlex

Sponsor our Newsletter | Privacy Policy | Terms of Service