I have a .bat file on our local network that processes a file on a local shared drive and saves it back to said local drive with a specific name.
I have a .php file on our web server (hosted externally with a hosting company) that takes that file- usually uploaded via a form in a web browser- and explodes it and and enters the data into a MySQL database (also on the external web server).
I want to modify the .bat file to 'send' the file to the external php script and run the external PHP file without opening a browser window. The purpose is to automate this entire process so our end users can just run the .bat file and the external database will be updated.
So far, all I can find is how to trigger .bat from PHP, which is the opposite of what I'm looking for. Our network does not have a web server OR PHP installed and they cannot be.
I found this for executing a local php file:
C:\PHP5\php.exe -f "C:\PHP Scripts\script.php" -- -arg1 -arg2 -arg3
I apologize if this is a stupid question- I'm a web developer and while my knowledge of web languages is great, my knowledge of languages like DOS is on par with a 3 year old.
Here's the php that I am currently working with (this will be modified a bit but the basic functionality will be the same:
include "dbcommon.php";
//connect to the database
$conn = mysql_connect($dbhost,$username,$password) or die ("Could not connect to the employee database");
@mysql_select_db($dbname,$conn);
$uploaded_file = "employees.csv";
if ( move_uploaded_file ($_FILES['infilename'] ['tmp_name'], $uploaded_file) )
{ //open uploaded file
$result = file_get_contents($uploaded_file);
if ($result === false)
{
$error = "Could not read $uploaded_file.<br>";
}
else
{
$error ="";
$query = "DELETE FROM employees";
$delresult = mysql_query($query,$conn);
if (!$delresult)
$error .= '<br>Error deleting existing employee records.';
$lines = explode("\r\n", $result);
foreach ($lines as $line)
{
$field = explode(",", $line);
$employee_id = str_replace('"','', $field[0]);
$last_name = addslashes(str_replace('"','', $field[1]));
$first_name = addslashes(str_replace('"','', $field[2]));
$supervisor_id = str_replace('"','', $field[3]);
// If all required fields have a value, insert the row
if ($employee_id != "" && $last_name != "" && $first_name != "")
{
$query="INSERT INTO employees (employee_id, last_name, first_name, supervisor_id) VALUES ('$employee_id', '$last_name', '$first_name', '$supervisor_id')";
$result = mysql_query($query,$conn);
if (!$result)
$error .= '<br>Error inserting "'.$employee_id.'","'.$last_name.','.$first_name.'","'.$supervisor_id.'"';
}
// If any required field has a value set, report the error
elseif ($employee_id != "" || $last_name != "" || $first_name != "")
{
$error .= '<br>Error inserting "'.$employee_id.'","'.$last_name.','.$first_name.'","'.$supervisor_id.'"';
}
}
if ($error == "")
$error = "Successfully uploaded and inserted the employee records.";
}
} else {
$error = "";
switch ($_FILES['infilename'] ['error'])
{
case 1:
$error .= '<p> The file is bigger than this PHP installation allows</p>';
break;
case 2:
$error .= '<p> The file is bigger than this form allows</p>';
break;
case 3:
$error .= '<p> Only part of the file was uploaded</p>';
break;
case 4:
$error .= '<p> No file was uploaded</p>';
break;
default:
$error .= '<p>'.$_FILES['infilename'] ['error'].'</p>';
break;
}
}
echo $error;
//close the database connection
mysql_close($conn);
Any help is greatly appreciated!