php - Yii resumable implementing -


i have task implement resumable in yii, , implemented upload control, never resumable before.

public function actionupload()     {         $model=new user;         if(isset($_post['user'])) {              $model->attributes=$_post['user'];              $model->image=cuploadedfile::getinstance($model,'image');              if($model->save()) {                  $model->image->saveas('upload/'.$model->image->name);                  $this->redirect(array('view','id'=>$model->uuserid));              }         }         $this->render('upload',array('model'=>$model));     } 

the task chunk file in small pieces.

example: 1 file can 1 gb. , try send file rest service.

see sample server implementation in php

i copy-paste here essential part of code, provided on page:

/**  *  * check if parts exist, ,   * gather parts of file  * @param string $dir - temporary directory holding parts of file  * @param string $filename - original file name  * @param string $chunksize - each chunk size (in bytes)  * @param string $totalsize - original file size (in bytes)  */ function createfilefromchunks($temp_dir, $filename, $chunksize, $totalsize) {      // count parts of file     $total_files = 0;     foreach(scandir($temp_dir) $file) {         if (stripos($file, $filename) !== false) {             $total_files++;         }     }      // check parts present     // size of last part between chunksize , 2*$chunksize     if ($total_files * $chunksize >=  ($totalsize - $chunksize + 1)) {          // create final destination file          if (($fp = fopen('temp/'.$filename, 'w')) !== false) {             ($i=1; $i<=$total_files; $i++) {                 fwrite($fp, file_get_contents($temp_dir.'/'.$filename.'.part'.$i));                 _log('writing chunk '.$i);             }             fclose($fp);         } else {             _log('cannot create destination file');             return false;         }          // rename temporary directory (to avoid access other          // concurrent chunks uploads) , delete         if (rename($temp_dir, $temp_dir.'_unused')) {             rrmdir($temp_dir.'_unused');         } else {             rrmdir($temp_dir);         }     }  } 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -