
Originally Posted by
misson
OK - thanks for the starting point. This page didn't exactly help, but it did lead me to a similar helpful one...
I now have a 3 page process.
1) upload file to tmp dir
PHP Code:
<form action="datapreview.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<label>
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<input name="userfile" type="file" size="80" />
</label>
<p>
<label>
<input type="submit" name="button" id="button" value="Upload" />
</label>
</p>
</form>
2) Check data and preview
PHP Code:
<h2>File Information</h2>
<br />
File Name: <?php echo $_FILES['userfile']['name'];?>
<br />
File Type: <?php echo $_FILES['userfile']['type'];?>
<br/>
File Size (bytes): <?php echo $_FILES['userfile']['size'];?>
<br/>
Temp Uploaded File Name: <?php echo $_FILES['userfile']['tmp_name'];?>
<br/>
Error Code: <?php echo $_FILES['userfile']['error'];?>
<br/>
<br/>
<h2>Preview Data to be imported</h2>
<?php
$filecontent = file_get_contents($_FILES['userfile']['tmp_name']);
echo "<br/>";
print_r($filecontent);
?>
3) import into DB
Don't think I'll have any problems here.
My questions are..
a) how do I verify that the file is .csv format?
b) on page 2, how do I get the data to preview in tabular format? Will this have to be on a loop and create rows based on exploding by /n?
c) what happens to the temporary file? Is it automatically deleted on browser closure?