I am trying to upload a txt file to MYSQL database periodically as the txt file contents changes with time. I have 2 files: db.php and uploader.php. Below is the code for db.php
<html>
<head>
<title>File Uploading Form</title>
</head>
<body>
<h3>File Upload:</h3>
Select a file to upload: <br />
<form action="uploader.php" method="post"
enctype="multipart/form-data">
<input type="file" onchange="this.form.submit()" name="file" size="50" />
<br />
</form>
</body>
</html>
And the code for uploader.php
<?php
$contents = file_get_contents($_FILES['file']['tmp_name'])
or die( "Could not copy file!");
$username = "username";
$password = "password";
$hostname = "localhost";
//connection to the database
$connection=mysql_connect ($hostname, $username, $password)
or die("Unable to connect to MySQL");
//select a database to work with
$selected = mysql_select_db("test",$connection)
or die("Could not select examples");
$result2 = mysql_query("INSERT INTO testtable(data) VALUES (". $contents. ")");
mysql_close($connection);
?>
Upon running the program, I have to browse for my txt file and will be redirected to uploader.php. Data is then sent to my database. As data is being written to the txt file in my pc periodically, I need to upload the file to my database again automatically without the need to browse for the txt file again. The question is, how can I do that? If I were to manually refresh the webpage periodically, the new data will be sent to my database but of course, I wouldn't want to manually refresh the page as it is impractical. I tried adding <META HTTP-EQUIV="refresh" CONTENT="5">
which refreshes the page every 5s but this does not work
I am very new to php so I would really appreciate if the answers are simple and easy to understand. Thank you very much for your help.