Download from Menu List

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fernado1283
Forum Newbie
Posts: 22
Joined: Mon Aug 25, 2003 2:00 am

Download from Menu List

Post 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
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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).
Last edited by McGruff on Wed Aug 10, 2005 8:31 pm, edited 1 time in total.
fernado1283
Forum Newbie
Posts: 22
Joined: Mon Aug 25, 2003 2:00 am

Post 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
?>
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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.
Post Reply