Hi everyone

I want to add all text files in a given directory to a html combo box, when the user selects a file, I have one php script which takes the file and adds it to mysql query LOAD DATA INFILE!

I have successfully loaded data from a given file, but only when the file is hardcoded like: LOAD DATA INFILE 'C:\myfiles\data.txt'.

I want to get this file from a list in the combo box, please help!!

9 Years
Discussion Span
Last Post by somedude3488

i use this to display the code on my server so i don't have to ftp all the time to see errors.

you can make some changes to it so it will work for you. just to let you know its not complete but works. i didn't add the extension validation yet, but the directory stuff works.


$dir = dirname(__FILE__);
$allowed = array('php');
$directories = array('private','public_html','demo','classes','config','cron');

$files = array();

function listFiles($dir) {
	global $files,$directories;
	if (is_dir($dir)) {
		$open = opendir($dir);
		if (!$open) {
			die('Unable to open directory: ' . $dir);
		else {
			while (($file = readdir($open)) !== false) {
				if ($file !== '.' && $file !== '..') {
					$name = $dir . '/' . $file;
					if (is_dir($name)) {
						if (in_array($file,$directories)) {
					else {
						$files[] = $name;
	else {
		die($dir . ' is not a directory');


echo '<form action="' . $_SERVER['PHP_SELF'] . '" method="get">';
echo '<select name="file" onchange="this.form.submit()">';
echo '<option value=""></option>';
foreach($files as $file) {
	echo '<option value="' . $file . '">' . str_replace($_SERVER['DOCUMENT_ROOT'],'',$file) . '</option>';
echo '</select>';
echo '</form>';

if (isset($_GET['file'])) {
	$file = $_GET['file'];
	$open = fopen($file,'r');
	if ($open) {
		$i = 1;
		echo '<div style="width:80%;height:600px;"><pre>';
		while (!feof($open)) {
			$buffer = fgets($open, 4096);
			echo htmlentities($buffer);
		echo '</pre></div>';


i created it in about 10 minutes so it not perfect.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.