Forum Moderators: coopster

Message Too Old, No Replies

Present file for download

using form

         

d40sithui

2:53 pm on Aug 17, 2007 (gmt 0)

10+ Year Member



Hey guys,
I was using my contract company's website to download a pdf. Basically they provide a form, with radio buttons. after i select a radio, the file download prompt window pops up for me to download the file. How can this be done?
any ideas?

whoisgregg

3:09 pm on Aug 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have javascript create an iframe linked to the pdf file. :)

If that makes it display the pdf instead of download it, then link to a php file that sends the correct download header [php.net].

WesleyC

3:10 pm on Aug 17, 2007 (gmt 0)

10+ Year Member



<?php

//Block possible hack attempts by removing all slashes from the input--you may need to change this depending on your scenario
$file = preg_replace( "/[\/\\\\]/", "", $_POST["file"] );

if ( is_file( $file ) )
{
header( "Location: ".$file );
}
else
{
echo "Invalid file!";
}

?>

<form action="./this_page.php" method="POST">
<input type="radio" name="file" value="file1.pdf">
<input type="radio" name="file" value="file2.pdf">
</form>

whoisgregg

5:09 pm on Aug 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That code will do a redirect to the pdf file, but to force a download dialog you should look at Example 1574. Download dialog on the header manual page [php.net].

d40sithui

5:16 pm on Aug 17, 2007 (gmt 0)

10+ Year Member



hey thanks guys,
you've been most helpful!