嗨我正在yii做多个文件上传...
我有设置表单,可以像这样使用多个文件上传...
myfrom.php
<?php
$form=$this->beginWidget('CActiveForm', array(
'id'=>'topic-form',
'enableAjaxValidation'=>false,
'htmlOptions' => array('enctype' => 'multipart/form-data'), // ADD THIS
));
?>
<div class="row">
<?php
$this->widget('CMultiFileUpload', array(
'name' => 'imagepath',
'model'=> $model,
'attribute'=>'imagepath',
'accept' => 'jpeg|jpg|gif|png', // useful for verifying files
'duplicate' => 'Duplicate file!', // useful, i think
'denied' => 'Invalid file type', // useful, i think
));
?>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
我的控制器方法看起来像......
public function actionMultipleupload()
{
$model= new Uploadimage();
if(isset($_POST['Uploadimage']))
{
var_dump("inside if");
// $images = CUploadedFile::getInstancesByName('images');
}
var_dump("out side if");
$this->render('multipleupload',array('model'=>$model));
}
但是只有当我使用多文件上传小部件时,它才会进入循环...
它可以正常运行单个文件上传(如下所示)并上传...但它在多个文件上传中显示问题..
<div class="row">
<?php echo $form->labelEx($model,'imagepath'); ?>
<?php echo CHtml::activeFileField($model,'imagepath',array('size'=>60,'maxlength'=>500)); ?>
<?php echo $form->error($model,'imagepath'); ?>
</div>
我不知道我的代码出了什么问题......我指的是这篇文章
答案 0 :(得分:0)
由于您使用的是attribute
窗口小部件选项,因此不应使用name
:
$this->widget('CMultiFileUpload', array(
'model'=> $model,
'attribute'=>'imagepath',
'accept' => 'jpeg|jpg|gif|png', // useful for verifying files
'duplicate' => 'Duplicate file!', // useful, i think
'denied' => 'Invalid file type', // useful, i think
));
PS:下次你应该尝试一个简单的var_dump($_POST);