Hi everyone,
I have a text file with similar content as below:
admin,123
user,123
user2,123
What i need to perform is to upload the text file and read each lines. Then split the content of each lines by delimiter and add it to database. In my database there are two fields; user and password.
Any PHP Guru, Please guide me on this issue.
Thank in advance.
This is the code that i have used to split the uploaded data by lines.
<?
if (isset($_POST['Submit'])){
$fd = fopen ($form_data, "r");
$contents = fread ($fd,filesize ($form_data));
fclose ($fd);
$delimiter = ",";
$splitcontents = explode($delimiter, $contents);
$counter = "";
$lines = file($form_data);
foreach($lines as $line_num => $line)
{
echo $line;
echo "<br>";
}
}
?>
<form method="post" action="" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000">
<br>File to upload:<br>
<input type="file" name="form_data" size="40">
<p><input type="submit" name="Submit" value="Submit">
</form>