谁能帮我将代码从上传单个文件更改为多个文件上传?我尝试了很多示例,但似乎无法使其正常工作。颂如下。
<tr>
<td>Add file:</td>
<td><input type="file" name="cv" size="chars" class="Form" />
</td>
</tr>
<?php
include("lib/xmlrpc.inc");
include("settings.php");
include("header.php");
$post = $_POST;
$client = new xmlrpc_client($serverUri.'common');
$msg = new xmlrpcmsg('login');
$msg->addParam(new xmlrpcval($db, "string"));
$msg->addParam(new xmlrpcval($user, "string"));
$msg->addParam(new xmlrpcval($password, "string"));
$res = &$client->send($msg);
if(!$res->faultCode()){
$val = $res->value();
$id = $val->scalarval();
if (empty($id)){
echo "Connection error = ";
exit;
}
else
{
$client2 = new xmlrpc_client($serverUri.'object');
$val = array ("name" => new xmlrpcval($post['subject'],"string"),
"email_from" => new xmlrpcval($post['email'], "string"),
"partner_name" => new xmlrpcval($post['name'], "string"),
"partner_phone" => new xmlrpcval($post['phone'], "string"),
"description" => new xmlrpcval($post['letter'], "string"),
"job_id" => new xmlrpcval($post['jobid'], "int")
);
$msg = new xmlrpcmsg('execute');
$msg->addParam(new xmlrpcval($db, "string"));
$msg->addParam(new xmlrpcval($id, "int"));
$msg->addParam(new xmlrpcval($password, "string"));
$msg->addParam(new xmlrpcval("hr.applicant", "string"));
$msg->addParam(new xmlrpcval("create", "string"));
$msg->addParam(new xmlrpcval($val, "struct"));
$res2 = &$client2->send($msg);
if(!$res2->faultCode())
{
$val2 = $res2->value()->scalarval();
$tmp_name = $_FILES['cv']['tmp_name'];
$file_name = $_FILES['cv']['name'];
if(file_exists($tmp_name))
{
// open the file for a binary read
$file = fopen($tmp_name,'rb');
// read the file content into a variable
$data = fread($file,filesize($tmp_name));
// close the file
fclose($file);
// now we encode it and split it into acceptable length lines
$encodedFile = base64_encode($data);
$valFile = array ("name" => new xmlrpcval($file_name,"string"),
"datas" => new xmlrpcval($encodedFile, "string"),
"datas_fname" => new xmlrpcval($file_name, "string"),
"index_content" => new xmlrpcval("true", "string"),
"res_model" => new xmlrpcval("hr.applicant", "string"),
"res_id" => new xmlrpcval($val2, "int"),
);
$msgFile = new xmlrpcmsg('execute');
$msgFile->addParam(new xmlrpcval($db, "string"));
$msgFile->addParam(new xmlrpcval($id, "int"));
$msgFile->addParam(new xmlrpcval($password, "string"));
$msgFile->addParam(new xmlrpcval("ir.attachment", "string"));
$msgFile->addParam(new xmlrpcval("create", "string"));
$msgFile->addParam(new xmlrpcval($valFile, "struct"));
$res2File = &$client2->send($msgFile);
}
echo 'Thanks for applying, Files (name of file to be added) are uploaded.<br />';
echo '<a href="index.php">Back to start</a><br />';
}
else
{
echo "<br />Problem in message sending for create application";
}
}
}
else
{
echo "<br />Connection not established";
}
include("footer.php");
?>
<input name="cv" type="file" size="chars" class="Form" />