/** * Provides a way to an external application to upload PDB files by POST. */ public function actionUploadExternal() { // Determine what action to perform - // to check file presence or to do actual upload. $action = self::ACTION_UPLOAD; // Assume upload action by default if (isset($_POST['action'])) { if ($_POST['action'] == 'Check') { $action = self::ACTION_CHECK; } else { if ($_POST['action'] == 'UploadFile') { $action = self::ACTION_UPLOAD; } } } // Create new model instance $model = new DebugInfo('create'); // Fill model attributes if (isset($_POST['DebugInfo'])) { $model->attributes = $_POST['DebugInfo']; } // Check if file with such a GUID exists $fileNotFound = $model->checkFileGUIDExists(); // Determine what to do based on the "action" attribute if ($action == self::ACTION_CHECK) { // Just render the result of checking GUID presence. $this->renderPartial('_upload', array('model' => $model)); } else { // The following code is executed when action is self::ACTION_UPLOAD // Check if we have found such file in the database. If yes, we do not need // to upload another one. if ($fileNotFound && $model->validate()) { // Get uploaded file $model->fileAttachment = CUploadedFile::getInstance($model, 'fileAttachment'); // This will create a new record in the {{debuginfo}} db table $model->save(); } // Display the result $this->renderPartial('_upload', array('model' => $model)); } }