gpt4 book ai didi

php - 我正在尝试使用 codeigniter 框架使用 Jquery 和 ajax 函数上传图像。我可以看到错误 :

转载 作者:行者123 更新时间:2023-12-01 04:41:51 26 4
gpt4 key购买 nike

A PHP Error was encountered

Severity: Notice Message:

Undefined index: uploadimg

Filename: models/upload_model.php

Line Number: 26

我的代码:

Controller

public function do_upload(){
$this->upload->do_upload();
if($this->upload_model->Doupload()){
echo 1;
}else{
echo 0;
}
}
private function set_config_option(){
$config =array(
'allowed_type' => 'gif|jpg|png|jpeg|pdf|doc|xml|zip|rar',
'file_size' => '100',
'max_width' => '1024',
'overwrite' => TRUE,
'max_height' => '768',
);
return $config;
}

型号

 private function set_config_option(){
$config =array(
'allowed_type' => 'gif|jpg|png|jpeg|pdf|doc|xml|zip|rar',
'file_size' => '2048000',
'max_width' => '1024',
'overwrite' => TRUE,
'max_height' => '768'
);
return $config;
}

public function Doupload(){
$target_path = 'uploads/';
$target_file = $target_path. basename($_FILES['uploadimg']['name']);
$base_url = base_url();
$img_title = $this->input->post('imgname');

$this->upload->initialize('upload', $this->set_config_option());
// $img = $this->upload->do_upload();
}

请帮助我...

最佳答案

模型未接收 $_FILES 对象。为什么你将上传过程分成两个文件(模型和 Controller ?,你在数据库中存储一些东西?)。在 codeiniter 文档中:https://ellislab.com/codeigniter/user-guide/libraries/file_uploading.html全部在同一个文件( Controller )中。

尝试遵循示例或尝试在 Controller 中添加:

$this->upload_model->Doupload($_FILES);

在模型中:

public function Doupload($file){
$target_path = 'uploads/';
$target_file = $target_path. basename($file['uploadimg']['name']);

我猜您使用以下方式加载库: $this->load->library('upload'); 或通过自动加载配置类。希望对您有帮助!

关于php - 我正在尝试使用 codeigniter 框架使用 Jquery 和 ajax 函数上传图像。我可以看到错误 :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36100822/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com