我在本地网络上有一个.bat文件,该文件处理本地共享驱动器上的文件,并使用特定名称将其保存回所述本地驱动器。
我在我们的网络服务器(由托管公司外部托管)上有一个.php文件,该文件通常会通过网络浏览器中的表格上传,然后将该文件爆炸并将其输入到MySQL数据库中(也位于外部)网络服务器)。
我想修改.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);
任何帮助是极大的赞赏!
我认为您可能正在寻找以下其中一项:
卷曲
http://howes-it-going.com/curl_Windows_Example.html
SOAP / REST
SOAP第三方:
特别是,我认为您可能会在DOS的cURL或Windows的CygWin中找到某些东西(它提供了更好的cURL实现)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句