false, 'extensions' => 'png, jpg, jpeg, pdf, rar, zip', 'maxFiles' => 70], ]; } public function upload($params) { if ($this->validate()) { $currentStorage = Storage::findOne(['stt' => 1])->folder; // $root = \Yii::getAlias('@app') . '/web/data/uploads/'; $root = $currentStorage . "/uploads/"; $folder = $root . $params['project_type'] . "/" . $params['project_id'] . "/" . $params['p_id']; if (!file_exists($folder)) mkdir($folder, 0777, true); $files = []; foreach ($this->imageFiles as $file) { $file->saveAs($folder . "/" . $file->baseName . '.' . $file->extension); $files[] = $file->baseName . '.' . $file->extension; } $model = new Images(); $model->create($params, $files); $results = Results::findOne(['project_id' => $params['project_id_raw'], 'p_id' => $params['p_id_raw']]); $results->content = "yes"; if ($results->create_at == $results->modified_at) { $results->modified_at = time(); } $results->save(); return true; } else { var_dump($this->errors); return false; } } public function uploadZip($params) { return $this->UploadFile('file' . $params["name"], ["RAR", "ZIP", "MPG", "MXF"], $params); } public function uploadDoc($params) { return $this->UploadFile('file' . $params["name"], ["DOC", "DOCX", "XLS", "XLSX"], $params); } public function uploadWord($params) { return $this->UploadFile('file' . $params["name"], ["DOC", "DOCX", "RAR", "ZIP"], $params); } public function uploadMp3($params) { return $this->UploadFile('file' . $params["name"], ["MP3", "WAV", "RAR", "ZIP"], $params); } public function UploadFile($file, $fileTypes, $params) { $currentStorage = Storage::findOne(['stt' => 1])->folder; // $root = \Yii::getAlias('@app') . '/web/data/uploads'; $root = $currentStorage . "/uploads"; $LocalPath = "/" . $params['project_type'] . "/" . $params['project_id'] . "/" . $params['p_id']; $RootFolder = $root . $LocalPath; // $name = $_FILES[$file]["name"]; // $array = explode(".", $name); // $nr = count($array); // $ext = $array[$nr - 1]; // $fileName = md5($params['project_type'] . "/" . $params['project_id'] . "/" . $params['p_id']); $destfile = $_FILES[$file]["name"]; if (!empty($_FILES)) { $tempFile = $_FILES[$file]['tmp_name']; $targetPath = $RootFolder; if (!file_exists($targetPath)) { @mkdir($targetPath, 0777, true); } $targetFile = $targetPath . '/' . $destfile; $targetFileLocal = $LocalPath . '/' . $destfile; // Validate the file type $fileParts = pathinfo($_FILES[$file]['name']); if (in_array(strtoupper($fileParts['extension']), $fileTypes)) { move_uploaded_file($tempFile, $targetFile); if (file_exists($targetFile)) { return $targetFileLocal; } else { return false; } } else { return 2; } } } public function UploadGlobal($file, $fileTypes, $path) { $root = \Yii::getAlias('@app') . '/web/data/uploads'; $LocalPath = "/" . $path; $RootFolder = $root . $LocalPath; // $name = $_FILES[$file]["name"]; // $array = explode(".", $name); // $nr = count($array); // $ext = $array[$nr - 1]; // $fileName = md5($path); $destfile = time() . "_" . $_FILES[$file]["name"]; // time() . "_" . $fileName . "." . $ext; if (!empty($_FILES)) { $tempFile = $_FILES[$file]['tmp_name']; $targetPath = $RootFolder; if (!file_exists($targetPath)) { @mkdir($targetPath, 0777, true); } $targetFile = $targetPath . '/' . $destfile; $targetFileLocal = $LocalPath . '/' . $destfile; // Validate the file type $fileParts = pathinfo($_FILES[$file]['name']); if (in_array(strtoupper($fileParts['extension']), $fileTypes)) { move_uploaded_file($tempFile, $targetFile); if (file_exists($targetFile)) { return $targetFileLocal; } else { return false; } } else { return 2; } } } public function UploadSound($file, $fileTypes, $path) { $root = \Yii::getAlias('@app') . '/web/data'; $LocalPath = "/" . $path; $RootFolder = $root . $LocalPath; $destfile = "welcome_en.wav"; if (!empty($_FILES)) { $tempFile = $_FILES[$file]['tmp_name']; $targetPath = $RootFolder; if (!file_exists($targetPath)) { @mkdir($targetPath, 0777, true); } $targetFile = $targetPath . '/' . $destfile; $targetFileLocal = $LocalPath . '/' . $destfile; $fileParts = pathinfo($_FILES[$file]['name']); if (in_array(strtoupper($fileParts['extension']), $fileTypes)) { move_uploaded_file($tempFile, $targetFile); if (file_exists($targetFile)) { return $targetFileLocal; } else { return false; } } else { return 2; } } } //Move file public function MoveFile($file, $folder) { $currentStorage = Storage::findOne(['stt' => 1])->folder; $root = $currentStorage . "/uploads"; // $root = \Yii::getAlias('@app') . '/web/data/uploads/'; $tempdir = $file; if (trim($tempdir) !== "") { $tempdir = $root . trim($tempdir); } else { $tempdir = "/dddddddddddddddddddddeeeeeeeeeeeee"; } if (file_exists($tempdir)) { $destfile = basename($tempdir); $dir = $root . $folder; $file_dir = $dir . '/' . $destfile; $link = $destfile; if (!file_exists($dir)) { @mkdir($dir, 0777, true); } $output = shell_exec("mv {$tempdir} {$file_dir}"); } else { $link = $file; } return $link; } }