Example #1
0
 public function testRpos()
 {
     $this->assertNull(StringHelper::rpos(null, 'sad'));
     $this->assertNull(StringHelper::rpos('a', 'sad', 10));
     $this->assertEquals(1, StringHelper::rpos('lakanahbaha', 'a', -1));
     $this->assertEquals(10, StringHelper::rpos('lakanahbahakjlapaosa', 'a', -5));
     $this->assertEquals(19, StringHelper::rpos('lakanahbahakjlapaosa', 'a', 1));
     $this->assertEquals(16, StringHelper::rpos('lakanahbahakjlapaosa', 'a', 2));
 }
Example #2
0
 public function actionIndex()
 {
     $this->title = Yii::t('vps-uploader', 'File list');
     $query = File::find();
     $provider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['dt' => SORT_DESC]], 'pagination' => ['pageSize' => 50, 'forcePageParam' => false, 'pageSizeParam' => false, 'urlManager' => new \yii\web\UrlManager(['enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => ['uploader/file/<page>' => 'uploader/file/index']])]]);
     // Last uploaded files.
     $last = Yii::$app->request->get('last', '');
     $this->data('last', StringHelper::explode($last));
     // Common files list.
     $this->data('files', $provider->models);
     $this->data('pagination', $provider->pagination);
 }
Example #3
0
 /**
  * Saves uploaded file.
  * @param null|string $name File name (without extension).
  * @return string Saved file name with extension.
  * @throws \yii\base\ErrorException
  */
 public function save($name = null)
 {
     if ($name == null) {
         $name = StringHelper::random();
     }
     $ext = pathinfo($this->_params['filename'], PATHINFO_EXTENSION);
     $this->_savedFilename = $name . '.' . $ext;
     if (($file = fopen($this->_targetDir . '/' . $this->_savedFilename, 'w')) !== false) {
         if (Yii::$app->settings->get('upload_concat') == 'cat') {
             fclose($file);
             setlocale(LC_ALL, 'ru_RU.UTF-8');
             for ($i = 1; $i <= $this->_params['totalChunks']; $i++) {
                 shell_exec('cat ' . escapeshellarg($this->getChunkPath($i)) . ' >> ' . escapeshellarg($this->_targetDir . '/' . $this->_savedFilename));
             }
             setlocale(LC_ALL, null);
         } else {
             for ($i = 1; $i <= $this->_params['totalChunks']; $i++) {
                 fwrite($file, file_get_contents($this->getChunkPath($i)));
             }
             fclose($file);
         }
     }
     FileHelper::removeDirectory($this->_tmpDir);
     return $this->_savedFilename;
 }