我在本地网络上有一个。bat文件,它处理本地共享驱动器上的文件,并将其保存回指定名称的本地驱动器。
我有一个。php文件在我们的web服务器(托管与托管公司外部),该文件-通常通过在web浏览器中的表单上传-并爆炸它,并将数据输入到MySQL数据库(也在外部web服务器上)。
我想修改。bat文件以"发送"文件到外部php脚本并运行外部php文件而不打开浏览器窗口。目的是使整个过程自动化,这样我们的最终用户可以只运行。bat文件,外部数据库将被更新。
到目前为止,我所能找到的就是如何从PHP触发。bat,这与我正在寻找的相反。我们的网络没有安装web服务器或PHP,他们不能。我发现这个用于执行本地php文件:
C:'PHP5'php.exe -f "C:'PHP Scripts'script.php" -- -arg1 -arg2 -arg3
如果这是一个愚蠢的问题,我很抱歉——我是一名web开发人员,虽然我对web语言的知识很丰富,但我对DOS等语言的知识只相当于一个3岁的孩子。
这是我目前正在使用的php(这将被修改一点,但基本功能将是相同的):
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);
任何帮助都非常感谢!
我想你可能在寻找以下内容之一:
旋度从Windows控制台运行cURL命令
http://howes-it-going.com/curl_Windows_Example.html如何在Windows下使用curl发布PUT请求?
使用curl命令行发送/post XML文件
SOAP/REST
具象状态传输(REST)和简单对象访问协议(SOAP)
SOAP第三方:WinBatch - commercial,优秀的支持
AutoHotKey - free,不太热的支持
biterScripting - unknown
特别是,我认为你可能会在DOS的cURL中找到一些东西,或者通过CygWin for Windows(它提供了更好的cURL实现)