Tuesday, 6 August 2013

Php get option value from select menu with variable

Php get option value from select menu with variable

There is the code in index.php:
<select name="select" id="select_invoice">
<option value="">--- Please select ---</option>
<?php echo $obj->printOption(); ?>
</select>
The class is follow:
class SelectOption {
private $query_names;
private $selected_index = '';
public function SelectOption($query_names=''){
if($query_names) $this->query_names = $query_names;
if($query_names) $this->query_names = $query_names;}
public function printOption(){
echo $this->getOption();}
public function get_diretory($query_names) {
print '<select name="files">';
$directory = dir($query_names) or die($php_errormsg);
print '<option> --Please select-- </option>';
while (false !== ($f = $directory->read())) {
if (is_file($directory->path.'/'.$f)) {
print '<option> ' . $f . '</option>';}}
$directory->close();}}
$query_names = 'file_directory';
$obj = new SelectOption($query_names);
$obj->get_diretory($query_names);?>
How can I get the option value from this select menu and find the file in
the directory and read it?
Thank you!

No comments:

Post a Comment