我正在准备一个**CMS,其中有使命,愿景,和为什么_我们部分。**我想,而编辑我应该上传三个图像分别与不同的文本字段提供对每个部分。整个条目和图像应该反映在SQL数据库。样本代码如下所述,请协助。
查看代码
<form method="post" action="<?php echo site_url('about_us/insertdata');?>" enctype="multipart/form-data">
<!-- ============================================================= -->
<!-- Section for traavnow vision starts here -->
<!-- Section for our vision text data starts here -->
<div class="form-group row">
<label for="staticEmail" class="col-sm-2 col-form-label">Our Vision:</label>
<div class="col-sm-10">
<textarea class="form-control" id="vision" name="our_vision" rows="3"></textarea>
</div>
</div>
<!-- Section for our vision text data ends here -->
<!-- Section for Uploading Image File to Our Vision Section Starts here -->
<div class="form-group row">
<label for="staticEmail" class="col-sm-4 col-form-label" >Upload Image:</label>
<div class="col-sm-4">
<input type="file" class="form-control-file" id="vision_image" name="vision_image">
</div>
<div class="col-sm-4" style="margin-top: 24px;">
<img src="" class="img-fluid rounded table-bordered" alt="Vision Image" style="height: 110px; width: 110px;">
</div>
</div>
<!-- Section for Uploading Image File to Our Vision Section ends here -->
<!-- Section for traavnow vision ends here -->
<!-- ============================================================= -->
<!-- ============================================================= -->
<!-- Section for traavnow mission starts here -->
<!-- Section for our mission text data starts here -->
<div class="form-group row">
<label for="staticEmail" class="col-sm-2 col-form-label">Our Mission:</label>
<div class="col-sm-10">
<textarea class="form-control" id="mission" name="our_mission" rows="3"></textarea>
</div>
</div>
<!-- Section for our mission text data ends here -->
<!-- Section for Uploading Image File to Our mission Section Starts here -->
<div class="form-group row">
<label for="staticEmail" class="col-sm-4 col-form-label">Upload Image:</label>
<div class="col-sm-4">
<input type="file" class="form-control-file" id="mission_image" name="mission_image">
</div>
<div class="col-sm-4" style="margin-top: 24px;">
<img src="" class="img-fluid rounded table-bordered" alt="Mission Image" style="height: 110px; width: 110px;">
</div>
</div>
<!-- Section for Uploading Image File to Our mission Section ends here -->
<!-- Section for traavnow mission ends here -->
<!-- ============================================================= -->
<!-- ============================================================= -->
<!-- Section for traavnow why_traavnow starts here -->
<!-- Section for our why_traavnow text data starts here -->
<div class="form-group row">
<label for="staticEmail" class="col-sm-2 col-form-label">Why Traavnow:</label>
<div class="col-sm-10">
<textarea class="form-control" id="why_traavnow" name="why_traavnow" rows="3"></textarea>
</div>
</div>
<!-- Section for our why_traavnow text data ends here -->
<!-- Section for Uploading Image File to Our why_traavnow Section Starts here -->
<div class="form-group row">
<label for="staticEmail" class="col-sm-4 col-form-label">Upload Image:</label>
<div class="col-sm-4">
<input type="file" class="form-control-file" id="whyus_image" name="whyus_image">
</div>
<div class="col-sm-4" style="margin-top: 24px;">
<img src="" class="img-fluid rounded table-bordered" alt="Why Traavnow" style="height: 110px; width: 110px;">
</div>
</div>
<!-- Section for Uploading Image File to Our why_traavnow Section ends here -->
<!-- Section for traavnow why_traavnow ends here -->
<!-- ============================================================= -->
<!-- ============================================================= -->
<!-- Button responding to form submission starts here -->
<div class="form-group row">
<label for="staticEmail" class="col-sm-2 col-form-label"></label>
<div class="col-sm-10">
<button class="btn btn-primary form-control" name="update" type="submit">Update Details</button>
</div>
</div>
<!-- Button responding to form submission ends here -->
<!-- ============================================================= -->
<div style="height: 120px;"></div>
</form>
- 控制器代码 *
// Function to INSERT text and images against each text starts here
public function insertdata()
{
$vision = $this->input->post('our_vision');
$mission = $this->input->post('our_mission');
$why_traavnow = $this->input->post('why_traavnow');
// get foto
$config['upload_path'] = './assets/uploads/about_us/';
$config['allowed_types'] = 'jpg|png|jpeg|';
$config['max_size'] = '2048'; //2MB max
$config['max_width'] = '4480'; // pixel
$config['max_height'] = '4480'; // pixel
$config['file_name'] = $_FILES['vision_image']['name'];
$this->upload->initialize($config);
if (!empty($_FILES['vision_image']['name'] ))
{
if ( $this->upload->do_upload('vision_image') ) {
$photo = $this->upload->data();
$data = array(
'our_vision' => $vision,
'photo' => $photo['vision_image'],
'our_mission' => $mission,
'why_traavnow' => $why_traavnow,
);
if(isset($_FILES) && ){
$this->model("about_us_model/insert");
}
}else {
echo "<script>alert('Details Updated Successfully')</script>";
}
}
}
型号代码
public function insert($data)
{
$this->db->insert('about_us',$data);
return TRUE;
}
1条答案
按热度按时间o7jaxewo1#
根据您的图片:-
备注:-
首先在
assets/uploads/about
目录中创建一个名为about
的文件夹,并在该文件夹中存储3个不同的图像,然后在about_us
数据库表中插入扩展名为的文本和图像路径。控制器代码:- About_us
查看部分:- edit_about_us.php
注意:-关于生成查询结果:-
https://codeigniter.com/userguide3/database/results.html
关于文件上传:-
https://codeigniter.com/userguide3/libraries/file_uploading.html