【发布时间】:2009-10-20 06:07:33
【问题描述】:
我正在尝试在我的应用程序中使用文件上传功能..
我有一个表单,其中包含许多 Text、textarea 类型的字段,包括文件上传字段。
我在表单末尾保留了一个提交按钮,单击该按钮将提交文本框 /textarea 的实际值,甚至是文件上传类型的字段的值。
如何获取上传的实际文件并将其保存在某个位置,以便我以后可以查看上传的文件..
我使用的代码是, 编辑:
我在表单标签中添加了enctype,但在提交时不起作用
<form method="post" action="/FormBuilder/index.php/forms/submit/93/13" id="ResultSubmit" enctype="multipart/form-data">
<div class="input file">
<label for="276">Choose Ur File To Upload</label>
<input type="file" value="" style="width: 400px;" id="276" name="Choose ur file to upload"/>
</div><br/>
<div class="input text">
<label for="277">Name</label>
<input type="text" value="" style="width: 200px;" id="277" name="Name"/>
</div> <br/>
<div class="submit"><input type="submit" value="submit"/></div>
</form>
Cakephp 控制器中的 Action Submit 是
function submit($formid = null,$fillerid=null)
{
$this->data['Result']['form_id']=$formid;
$this->data['Result']['submitter_id']=$fillerid;
$this->data['Result']['submitter']=$this->Session->read('filler');
echo "submitter: ".$this->Session->read('filler');
$results=$this->Form->hasResults($this->data);
echo http_build_query($_POST);
if(empty($results)){
foreach ($_POST as $key => $value):
if(is_array($value)){
$value = implode('', $_POST[$key]);
$this->data['Result']['value']=$value;
}
else{
$this->data['Result']['value']=$value;
}
$this->data['Result']['form_id']=$formid;
$this->data['Result']['submitter_id']=$fillerid;
$this->data['Result']['label']=Inflector::humanize($key);
$this->data['Result']['submitter']=$this->Session->read('filler');
$this->Form->submitForm($this->data);
endforeach;
$this->Session->setFlash('Your entry has been submitted.');
$this->Invite->updateAll(array('Invite.filled'=>"'Yes'"),array('Invite.id'=>"$fillerid"));
}else{
$this->Session->setFlash('You have already filled the Form .');
}
}
【问题讨论】:
-
嗨,如果我在 Form 标签中添加 enctype 它不起作用
-
你开始使用 Cake 怎么样?尝试完全按照手册中的说明进行操作。 (提示:您的具体问题是文件字段的名称,但更大的问题是您没有使用 Cake。)
-
即使我的字段为 如何从数据中获取 Untitled3 [Form][Untitled3] 以便使用它通过 $this->data['Form']['Untitled3']['tmp_name']; 获取 tmp_name;
标签: cakephp