2014-09-03 80 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的東西。我在編程新手。希望對你有所幫助)