I have an html form to open a file. All I need is the file name and path. All of the instructions I have found are for a file upload. Anyhoo, here's the code I stole:

<form enctype="multipart/form-data" action="ImportTOA.php" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <br /><input name="userfile" type="file" />
    <input type="submit" value="Send File" />
</form>

What I want is a no-muss-no-fuss open file dialog. This script has two buttons, and I only want one to open the dialog and the submit button on the dialog to pass the file name to my action file.

Here's the action file with a bug somewhere or how:

$ImportFile = $_FILES['userfile']['name'];


echo strrchr($ImportFile,'.');

if (strrchr($ImportFile,'.') != '.csv');  //for some reason or another this statement always 
                                                 //returns true. I can tell by the echo that the strrchr is 
                                                //returning '.csv'
	{
	echo 'Invalid File Type. Please re-enter';
	echo '<IMG class="displayed" src="Images/tivodance.gif" width="350px" height="250" />';
	echo '<script>';
		echo 'setTimeout(function(){window.location.href="Index.php"},1000)';
	echo '</script>';
	die();
	}


$TimsPath = "TOA_March/"; // how can I pass the path from the open file dialog?
chdir ($TimsPath);
$ReadFile = fopen($ImportFile, "r") or die("You dope, this file is unreachable");

 while (($buffer = fgets($ReadFile)) !== false) {

$LineArray = explode(",", $buffer);

Everything works, except for the condition routine.

As usual, your help is greatly appreciated.

    It might be possible to pass along the full path using some Java or Flash object, but you certainly can't do that using only HTML.

    Furthermore, it makes no sense to try to [man]chdir/man to that path even if you could get it unless you're making some assumption like the server's hard drive is a mirror of the user's.

      bradgrafelman;11024911 wrote:

      It might be possible to pass along the full path using some Java or Flash object, but you certainly can't do that using only HTML.

      Furthermore, it makes no sense to try to [man]chdir/man to that path even if you could get it unless you're making some assumption like the server's hard drive is a mirror of the user's.

      Yes, the server is a mirror of my laptop. Before I put in the 'chdir()' statement, I tried every path I could think of, and nothing worked until I put in the 'chdir()'.

      I just really love people who tell me 'furthermore' something doesn't make sense. There are ways to say a sentence without being insulting. To top that off, your sentence is grammatically incorrect.

        It always amazes me how rude and spiteful some ignorant people can be when asking for others to help them.

          Write a Reply...