【发布时间】:2012-11-01 16:17:01
【问题描述】:
谁能帮我将我的代码从上传单个文件更改为多个文件上传?我尝试了很多示例,但似乎无法使其正常工作。颂歌如下。
<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" />
【问题讨论】:
-
您似乎忘记在问题中包含您的代码。
-
是的,我现在刚刚添加,但有点梨形。
-
你尝试过什么转换?什么没试过?
-
我尝试了一些我发现的例子,比如使用 Foreach()。可能更多是因为我缺乏知识。我基本上想使用一个提交按钮一次添加多个文件。
-
我投票决定在您的代码出现之前结束您的问题。一旦您投票关闭,就无法撤消它;但我已经提名这个重新开放。另外,你在哪里声明你是这个论坛的新手?