Pagekit\Finder\Controller\FinderController::uploadAction PHP Method

uploadAction() public method

public uploadAction ( )
    public function uploadAction()
    {
        try {
            if (!($path = $this->getPath())) {
                return $this->error(__('Invalid path.'));
            }
            if (!is_dir($path) || 'w' !== ($mode = $this->getMode($path))) {
                throw new ForbiddenException(__('Permission denied.'));
            }
            $files = App::request()->files->get('files');
            if (!$files) {
                return $this->error(__('No files uploaded.'));
            }
            foreach ($files as $file) {
                if (!$file->isValid()) {
                    return $this->error(sprintf(__('Uploaded file invalid. (%s)'), $file->getErrorMessage()));
                }
                if (!$this->isValidFilename($file->getClientOriginalName())) {
                    return $this->error(__('Invalid file name.'));
                }
                $file->move($path, $file->getClientOriginalName());
            }
            return $this->success(__('Upload complete.'));
        } catch (\Exception $e) {
            return $this->error(__('Unable to upload.'));
        }
    }