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.