【发布时间】:2018-08-15 03:30:01
【问题描述】:
我在前端使用 Angular 4,在后端使用 CodeIgniter。在 angular 端,有一个表单,其中包含一些我需要在 CodeIgniter 端获取的输入值和图像,以便可以将它们保存在数据库中。但是对于图像,我希望将其保存在文件夹中,然后将其路径保存在数据库中
表格代码
<form ngNativeValidate [formGroup]="form" (ngSubmit)="onSubmitadd()" class="form-horizontal">
<input type="text" class="form-control" name="title" id="title" formControlName="title" minlength="10" maxlength="150" required>
<input type="file" id="avatar" (change)="onFileChange($event)" #fileInput required>
<button type="submit" class="demo-loading-btn btn red savebtn">Save</button>
</form>
onSubmitadd() {
const formModel = this.form.value;
this.loading = true;
this.http.post('http://www.localhost/litehires/company/profile',formModel ,{
})
.subscribe(
res => {
console.log(res);
$("#add-data .close").click();
this.listBanner();
},
err => {
console.log("Error occured");
}
);
}
控制器代码
public function profile()
{
$res = $this->input->post('formModel');
return $res;
}
在控制台中检查时,数据正在 formModel 中传递,但我无法在控制器中获取数据。谁能告诉我如何获取数据和图像,以便我可以进一步处理它
【问题讨论】:
-
在控制器中将
return $res;替换为print_r($res); -
打印 r 帖子和文件数组。有什么事吗?
-
@Alex 做了,但在控制台中我收到消息:发生错误
标签: php angular codeigniter file-upload upload