imageupload

This commit is contained in:
Sampanna Rimal 2024-07-16 17:52:18 +05:45
parent de0b041520
commit 7d973eeed5
3 changed files with 44 additions and 11 deletions

View File

@ -64,6 +64,19 @@ class Accountheads extends CI_Controller
case 'edit': case 'edit':
$id = $this->uri->segment(4); $id = $this->uri->segment(4);
if (isset($_POST['submit'])) { if (isset($_POST['submit'])) {
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$config['max_size'] = 128 * 1024;
$this->load->library('upload', $config);
if ($this->upload->do_upload('account_image')) {
$account_image_data = $this->upload->data();
$account_image = $account_image_data['file_name'];
}else{
$current_account_image = $this->db->query("SELECT account_image FROM tbl_accounts WHERE account_id = '$id'")->row()->account_image;
$account_image = $current_account_image;
}
// print_r($account_image);die;
$TableData = array( $TableData = array(
'accategory_id' => filter_var($_POST['accategory_id']), 'accategory_id' => filter_var($_POST['accategory_id']),
//'account_code' => filter_var($_POST['account_code']), //'account_code' => filter_var($_POST['account_code']),
@ -78,6 +91,7 @@ class Accountheads extends CI_Controller
'account_partyemail' => filter_var($_POST['account_partyemail']), 'account_partyemail' => filter_var($_POST['account_partyemail']),
'account_partycontactperson' => filter_var($_POST['account_partycontactperson']), 'account_partycontactperson' => filter_var($_POST['account_partycontactperson']),
'account_partycontactpersoncontact' => filter_var($_POST['account_partycontactpersoncontact']), 'account_partycontactpersoncontact' => filter_var($_POST['account_partycontactpersoncontact']),
'account_image' => $account_image,
'created_on' => date('Y-m-d H:i:s'), 'created_on' => date('Y-m-d H:i:s'),
'created_by' => 'admin', 'created_by' => 'admin',
'remarks' => filter_var($_POST['remarks']), 'remarks' => filter_var($_POST['remarks']),

View File

@ -60,7 +60,7 @@
<div class="col-2"> <div class="col-2">
<div class="text-center"> <div class="text-center">
<img class="profile-user-img img-fluid " src="../../dist/img/user4-128x128.jpg" alt="User profile picture"> <img class="profile-user-img img-fluid " src="<?php echo isset($Account->account_image) && $Account->account_image ? base_url('uploads/' . $Account->account_image) : base_url('/dist/img/user4-128x128.jpg'); ?>" alt="User profile picture">
</div> </div>
</div> </div>
<div class="col"> <div class="col">

View File

@ -20,15 +20,15 @@
</div> </div>
<div class="col-2"> <div class="col-2">
<div class="form-group"> <div class="form-group">
<label for="exampleInputFile">Upload Image</label> <label for="exampleInputFile">Upload Image</label>
<div class="input-group"> <div class="input-group">
<div class="custom-file"> <div class="custom-file">
<input type="file" class="custom-file-input" id="exampleInputFile"> <input type="file" class="custom-file-input" id="exampleInputFile" name="account_image" value="<?php echo $TableData->account_image; ?>" onchange="previewImage(event)">
<label class="custom-file-label" for="exampleInputFile">Choose file</label> <label class="custom-file-label" for="exampleInputFile">Choose file</label>
</div> </div>
</div>
</div>
</div>
</div>
</div> </div>
<div class="col-7"> <div class="col-7">
@ -66,6 +66,14 @@
</select> </select>
</div> </div>
</div> </div>
<!--image display-->
<div class="col-2">
<img id="imagePreview" class="profile-user-img img-fluid " src="<?php echo isset($TableData->account_image) && $TableData->account_image ? base_url('uploads/' . $TableData->account_image) : base_url('/dist/img/user4-128x128.jpg'); ?>" alt="Account Image" >
</div>
<!--image display end-->
<!--COL END--> <!--COL END-->
</div> </div>
<div class="row"> <div class="row">
@ -155,3 +163,14 @@
</div> </div>
</div> </div>
</div> </div>
<script>
function previewImage(event) {
var reader = new FileReader();
reader.onload = function() {
var output = document.getElementById('imagePreview');
output.src = reader.result;
}
reader.readAsDataURL(event.target.files[0]);
}
</script>