YII在Multi FIeld中使用CUploadedFile :: getInstance时出现问题

时间:2015-03-05 17:59:52

标签: yii

我需要帮助,我有50个文件字段,当我保存循环文件字段在26到50不保存文件,但文件字段1到25保存到数据库。在localhost xampp中它运行正确,但我托管到Web服务器的麻烦。谁知道问题是什么?这是我在控制器和表单中的代码

//form
<table>
<tr>
<td>
        <?php echo $form->labelEx($model,'mutu1'); ?>
        <?php echo CHtml::dropDownList(
                        'NilaiStandarMutu[mutu1]',$model->mutu1,
                        array(
                            ''=>'Pilihan',
                             'Ada'=>'Ada',
                            'Tidak Ada'=>'Tidak Ada',
                        )
                    );  
                ?>
        <?php echo $form->error($model,'mutu1'); ?>
</td>
<td style="padding-top:18px;padding-left:100px;padding-right:0px">  
        <?php //echo $form->labelEx($model,'file_mutu1'); ?>
        <?php echo $form->fileField($model,'file_mutu1',array('size'=>10)); ?>

        <?php echo $form->error($model,'file_mutu1'); ?>
</td>
<? 
if(!$model->isNewRecord)
{
?>
<td width=10%>
<? if($model->file_mutu1 <> "") { 
                echo CHtml::link('<i class="icon icon-search"></i> View File ',Yii::app()->baseUrl . "/FileUpload/".$model->file_mutu1, array('target'=>'_blank'));
            } else
            {
                echo CHtml::link('<i class="icon icon-remove"></i> Tidak ada File ','#');

            }

            ?>
</td>
<? } ?>
</tr>
<tr>
<td>
        <?php echo $form->labelEx($model,'mutu2'); ?>
        <?php echo CHtml::dropDownList(
                        'NilaiStandarMutu[mutu2]',$model->mutu2,
                        array(
                            ''=>'Pilihan',
                             'Berjalan'=>'Berjalan',
                            'Tidak Berjalan'=>'Tidak Berjalan',
                        )
                    ); 
                ?>
        <?php echo $form->error($model,'mutu2'); ?>
</td>

<td style="padding-top:18px;padding-left:100px">    
        <?php //echo $form->labelEx($model,'file_mutu1'); ?>
        <?php echo $form->fileField($model,'file_mutu2',array('size'=>10)); ?>
        <?php echo $form->error($model,'file_mutu2'); ?>
</td>
<? 
if(!$model->isNewRecord)
{
?>
<td width=10%>
<? if($model->file_mutu2 <> "") { 
                echo CHtml::link('<i class="icon icon-search"></i> View File ',Yii::app()->baseUrl . "/FileUpload/".$model->file_mutu2, array('target'=>'_blank'));
            } else
            {
                echo CHtml::link('<i class="icon icon-remove"></i> Tidak ada File ','#');

            }

            ?>
</td>
<? } ?>
</tr>
//....... until 50

//controller
    public function actionCreate()
        {
            $level = Yii::app()->user->getState("level");
            $username = Yii::app()->user->name;

            $month = substr(date('Y-m-d'),0,7); 

            $model=new NilaiStandarMutu;

            if(isset($_POST['NilaiStandarMutu']))
            {

                $model->attributes=$_POST['NilaiStandarMutu'];
                $file_standar_mutu->attributes=$_POST['FileStandarMutu']; 
                $i=1;
                $uploadedFile = array();
                $fileName = array();
                for ($i = 1; $i <= 50; $i++) 
                {
                    $rnd = rand(0,9999); 
                    $nama = 'file_mutu' . '' .$i;

                    $uploadedFile[$i]=CUploadedFile::getInstance($model,$nama);
                    //var_dump($uploadedFile['$i']);
                    $fileName[$i] = "{$rnd}-{$uploadedFile[$i]}";  // random number + file name
                    if(!empty($uploadedFile[$i]))
                    {

                        $model->$nama  = $fileName[$i];
                    } 
                }
                if($model->save())
                {
                    $arrlength = count($uploadedFile);
                    for($x = 0; $x <= $arrlength; $x++) {
                                if(!empty($uploadedFile[$x]))  // check if uploaded file is set or not
                                    {
                                        $uploadedFile[$x]->saveAs(Yii::app()->basePath.'/../FileUpload/'.$fileName[$x]);
                                    }
                            }

                    $this->redirect(array('view','id'=>$model->id_nilai_sm));

                }
            }


            if(isset($_GET[mode])=="new")
            {           
                if($level == "prodi")
                {
                        $model->CekJadwal();
                        $criteria = new CDbCriteria();
                        $criteria->select = 'tgl_input ';
                        $criteria->condition ="username='$username' and left(tgl_input,7)='$month'";
                        $find = NilaiStandarMutu::model()->count($criteria);
                        if($find >= 1)
                        {
                                Yii::app()->user->setFlash('error','Tambah gagal !!, Data sudah ada di tahun yang sama !!');
                                $this->redirect(array("admin"));

                        }   

                }
            }

            $this->render('create',array(
                'model'=>$model,
                'file_standar_mutu' => $file_standar_mutu,
            ));

        }

0 个答案:

没有答案