Page 1 of 1

Download from Menu List

Posted: Thu Aug 28, 2003 8:12 pm
by fernado1283
Hi,
I am having a trouble here. Can anyone please help me. I have a menu list of many jpg files that are in my folder. After I choose the file and press submit, I wanted it to be downloaded. Can anyone out there please help me. Thanks

Regards.
Fernado

Posted: Thu Aug 28, 2003 9:14 pm
by McGruff
Can you isolate a portion of code that isn't working as expected so we can help?

Perhaps the first thing to do when a form ain't working is add some debug lines to your script:

Code: Select all

<?php
echo '<pre>';
print_r($_POST);
echo '</pre>';
?>
.. assuming the form method is POST (which it should be).

Posted: Thu Aug 28, 2003 9:48 pm
by fernado1283
Hi,
This is what the code.
I can only open the file but I do not need to open the file but just only download the file when i click the submit button. Please help me. Thanks.

Code: Select all

<?php
if (isset($actionflag) && $actionflag == "download")
	{
		$passing = $selectXYZ;
	}
	
	$file_array = array();
	$file_array = getFiles($dir); // displays all the files in the folder

	print "<form action="test.php " name="selection" target="_blank">";
	print "<input type="hidden" name="actionflag" value="download">";
	print "<select name="selectXYZ">";

	foreach($file_array as $a_row)
	{

		// make sure it's not an include file or index file
		if (!strstr($a_row,".inc.php") && !strstr($a_row,"index.php") && !strstr($a_row, ".php"))
		{
			if (!is_dir($a_row)) // the file is not a directory
			{             
				print "<option>$a_row</option>";	
			}				
		}
	}

	print "</select> ";

	print "<input type="submit">";
	print "</form>";
?>

Regards
fernado
?>

Posted: Sat Aug 30, 2003 2:02 pm
by McGruff
Take a look at the header() function http://uk.php.net/manual/en/function.header.php.

I would define a form action pointed at a form processor which downloads the file and displays an appropriate page.

I should also point out that this is something I've never got around to looking at in detail so far but I hope that helps.