2014-09-03 75 views

回答

1

是的。这是我如何在Yii上进行多次上传。

public function actionCreate() 
{ 
    $model=new Screens; 
    if(isset($_POST['Screens'])) 
    { 
     $model->attributes=$_POST['Screens']; 
     if(isset($_FILES['screens'])){ 
      $images = CUploadedFile::getInstancesByName('screens'); 
      if(isset($images) && count($images)>0){ 
       foreach($images as $pic){ 
        $model->setIsNewRecord(true); 
        $pic->saveAs(Yii::getPathOfAlias('webroot.images.games.screens').DIRECTORY_SEPARATOR.$pic); 
        $model->image=$pic->name; 
        $model->game_id=1; 
        $model->save(); 
       } 
      } 
     } 
    } 
    $this->render('create',array(
     'model'=>$model, 
    )); 
} 

而我的观点:

 <?php 
     echo "Screens"; 
     $this->widget('CMultiFileUpload', array(
      'model'=>$model, 
      'name'=>'screens', 
      'attribute'=>'image', 
      'accept'=>'jpg|gif|png', 
     )); 
    ?> 

不要忘了加密类型。对不起,但我现在没有关于couchdb的东西。我在编程新手。希望对你有所帮助)