With the help of many on this site, we have been able to pull data and save it as a CSV file. We have 100+ computers that will be running this script locally and the uploading their respective CSV files to my server. The script will run every hour at :00. Every hour at :30, I will have a PHP script run that will input all the data from the CSV files into a MySQL database. This is where I need help.

I have attached the script I am using to import the information from the CSV into the MySQL database My goals:

  • Get the file name for entry into the database (I can pass this in the URL if needed)
  • Remove the erroneous three rows at the top of each CSV file (two blank rows and one header row)
  • Have the script cycle through and execute for all CSV's in the directory
  • Delete the CSV's after being imported

If it makes life easier, I can have the VBS remove the three lines. If I do so, will I need to remove the header row, or is that needed for input into the database?

My thought is that the individual laptops will run the script to get the data from stalist.cgi and upload the CSV every hour. Then, half-past every hour, this script will run that imports all CSV files into the database. This gives the computers time to process and upload and ensure I have the most accurate data possible.

Here is the script I have started with. As you can tell, I am specifying one particular CSV file to be read. I haven't figured out a way to have the script execute for all files. TIMTACULAR is the name of my computer, so you can see that the computer name is used the filename. It makes no difference to be whether the file name, or computer name (via URL) is used.

PHP Code:
$link_id mysql_connect("localhost""**""***") or die("Could not connect."); if(!mysql_select_db("speedtest",$link_id)) die("database was not selected.");$file_handle fopen("resultupload/TIMTACULAR.csv""r");while (($line_of_data fgetcsv($file_handle1000",")) !== FALSE) { $line_import_query="INSERT into bridges(MAC,DeviceName,SignalNoiseDBM,Distance,TxRxMbps,CCQ,ConnectionTime,LastIP) values('$line_of_data[0]','$line_of_data[1]','$line_of_data[2]','$line_of_data[3]','$line_of_data[4]','$line_of_data[5]','$line_of_data[6]','$line_of_data[7]')"mysql_query($line_import_query) or die(mysql_error()); } - Link to the actual CSV file being saved. - List of Columns in the database