gpt4 book ai didi

php - 如何将图像保存在CodeIgniter根文件夹和数据库中?

转载 作者:行者123 更新时间:2023-11-29 15:31:01 24 4
gpt4 key购买 nike

我需要让用户能够更改个人资料图片,但我找不到明确的文档来通过演示演练来展示 CodeIgniter 上传过程的工作原理。

我已经在主表中创建了一个名为 user_profile 的列。

我是 Controller ,我定义大小类型并对其进行加密。

public function update_profile(){

$config["upload_path"] = "public/images/profile";
$config["allowed_types"] = "jpg|jpeg|gif|png";
$config["max_size"] = 700;
$config["max_width"] = 1024;
$config["max_height"] = 768;
$config["encrypt_name"] = TRUE;

$this->load->library("upload", $config);

if($this->upload->do_upload('user_profile'))
{
$info_arquivo = $this->upload->data();
$user_profile = $info_arquivo["file_name"];

$this->load->model("profile_model");

$image_perfil = array(
"user_profile" => $user_profile
);

$query = $this->profile_model->insert_image($image_perfil);

if($query){
$this->session->set_flashdata('msg', 'Imagem de perfilfoi atualizada');
redirect(base_url('admin/dashboard'), 'refresh');
} else {
$this->session->set_flashdata('msg', 'Imagem de perfil não foi atualizada');
redirect(base_url('admin/profile'), 'refresh');
}
}
else
{
$this->session->set_flashdata('msg', 'Imagem de perfil não foi atualizada');
redirect(base_url('admin/profile'), 'refresh');
}

}

admin/profile View 中我放置了以下表单。

                <!-- UPLOAD IMAGE USER -->
<?php echo form_open_multipart('admin/update_profile'); ?>
<div class="form-group">
<label>Selecione uma imagem</label>
<input type="file" name="user_profile" class="form-control" id="user_profile" required/>
</div>
<div class="form-group">
<button type="submit" class="btn btn-success pull-right" value="cadastrar">Cadastrar</button>
</div>
</form>
<!-- END UPLOAD IMAGE USER -->

在我的 Profile_model 模型中,我将文件名插入user_profile

class Profile_model extends CI_Model{

public function insert_image($user_profile)
{
$this->db->insert('ci_users', $user_profile);

return $this->db->affected_rows() ? TRUE : FALSE;
}

}

最佳答案

我认为您的表单 URL 错误。请在下面的 HTML 表单中添加 index.php

   <!-- UPLOAD IMAGE USER -->
**<?php echo form_open_multipart('index.php/admin/update_profile'); ?>**
<div class="form-group">

关于php - 如何将图像保存在CodeIgniter根文件夹和数据库中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58734741/

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