I want to allow a user to browse a directory and select a file that then is put into a textfield, Any ideas on an approach to this in PHP?
Bret Lanius
Bret Lanius
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
<a href="<?php echo $_SERVER['PHP_SELF'].'&filename='.urlencode($dir.$file); ?>"><?php echo $file; ?>><br/>
<form action="filebutton.php" method=POST>
<select name="filething" size=5>
<?PHP
$dir="path\to\dir";
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
echo "<option value='$file'>" . $file . "</option>";
}
closedir($dh);
}
}
/*foreach (glob("*.php") as $filename) {
echo "<option value='$filename'>" . $filename . "</option>";
}*/
?>
</select>
<input type="textbox" name="filename" value="<?PHP if(isset($_POST['filething'])){echo $_POST['filething'];} else{echo "...";} ?>">
<input type=submit value="Put file into textbox">
</form>
<select name="myselect" size=5 Onchange="document.forms[0].[red]textboxname[/red].value=this.value;">