PHP dropdown menu option name help please
Posted: Thu Apr 01, 2010 9:06 am
Hi, I'm a noob when it comes to PHP and I'm learning but I'm stuck so please be kind to me.
I have a PHP dropdown menu that is populating using an array and it's working fine but I'd like to use a regular name as an option instead of the array name.
Here's the code. Could someone please show me how to display "test.php" instead of the path "pagedata/test.php". Thanks
I have a PHP dropdown menu that is populating using an array and it's working fine but I'd like to use a regular name as an option instead of the array name.
Here's the code. Could someone please show me how to display "test.php" instead of the path "pagedata/test.php". Thanks
Code: Select all
<?php
$dataFiles=array("pagedata/test.php","pagedata/data2.php","pagedata/data3.php","pagedata/data4.php","pagedata/data5.php","pagedata/data6.php","end_of_array");
for($i=0;$i<count($dataFiles)-1;$i++)
{
if(!file_exists($dataFiles[$i]))
{
$fp=fopen($dataFiles[$i],"w");
fwrite($fp," ");
fclose($fp);
}
else
{
if(filesize($dataFiles[$i])<=0)
{
$fp=fopen($dataFiles[$i],"a");
fwrite($fp," ");
fclose($fp);
}
}
}
$file=empty($_POST["source"])?"pagedata/test.php":$_POST["source"];//gg
if(!empty($_POST["current_file"]))
{
$data=empty($_POST['data'])?" ":$_POST['data'];
$file=$_POST["current_file"];
$fh=fopen($file,"w");
fwrite($fh,$data);
fclose($fh);
}
if(file_exists($file))
{
$fh=fopen($file,'r');
$data=stripslashes(fread($fh,filesize($file)));
fclose($fh);
}
?>
<div style="float:left;padding:5px 0 5px 0">
<form name="view_form" action="#" method="POST">
<select name="source" onchange="view_form.submit();">
<?php
for($i=0;$i<count($dataFiles);$i++)
{
$selected="";
if($dataFiles[$i]!="end_of_array")
{
if($file==$dataFiles[$i]){$selected="selected";}
echo "<option value='$dataFiles[$i]' $selected>$dataFiles[$i]</option>";
}
}
?>
</select></form></div>
<form action="#" method="post">
<input type="hidden" name="current_file" value="<?php echo $file; ?>"></form>