Пример #1
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;
 }
Пример #2
0
 public function testListRelativeFiles()
 {
     $this->assertNull(FileHelper::listRelativeFiles('ashdjghajsdgj', 'sadasd'));
     $this->assertEquals(['dir_1_2/dir_1_2_1/file5.txt', 'dir_1_2/file6.txt', 'dir_1_2/file7.txt'], FileHelper::listRelativeFiles($this->datapath . '/dir_1/dir_1_2', $this->datapath . '/dir_1'));
 }