Downloading Multiple Files

View/index.php:

I am using TbGridView with CCheckBoxColumn

and then Iam sending the id, of checked files to the controller using ajaxSubmit

MyController.php:

public function actionDownload() {


 $checked_files = array();

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

            $checked_files = $_POST['checked_files'];

}

What Next? :( in$checked_files , i have all the id of checked files.

This didit work for me:


 foreach ($checked_files as $key=>$value) {


              $model = $this->loadModel($value);

        // if ((!$model->originalFile->locked) || ($model->originalFile->lockedByUser(Yii::app()->user->id))) {

        $file = Yii::app()->file->set($model->path, true);


        $model->saveAttributes(array('file_name'));

        

        $filename = $model->id . '-' . $model->display_name . '.' . $model->extension;

       

        $file->send($filename);

            }



you cannot send multiple files in one http response… that is HTTP principle. you have to generate multiple http requests or pack all files in one archive (i.e. zip) and send that one archive

Oh thats sounds more complicated for me :(, iam areal newbie

would yu please explain more?

and thank you so much for your reply '“redguy”

just to add on to what redguy said, you have to send files one by one or you have to compress the files in on zip file and send that zip file to the user you cannot send more than file at once