Upload two images in codeigniter, but one of them is replace another image
up vote
0
down vote
favorite
image name in database only 'nama_ktp' and it must be two name, 1 is 'foto_ktp' and name 2 is 'foto_laporan'
Controller : Pelaporan.php
public function __construct()
{
parent::__construct();
$this->load->model('M_pelaporan','pelaporan');
}
public function index()
{
$data['konten']='pelaporan';
$this->load->view('template', $data);
}
public function tambah_laporan()
{
# code...
$foto_ktp = $_FILES['foto_ktp']['name'];
$foto_laporan = $_FILES['foto_laporan']['name'];
if($foto_ktp !== ""){
if(file_exists($upload_dir.$file_name)){
show_error('file already exist');
}
else{
$config['upload_path'] = './assets/img/';
$config['log_threshold'] = 1;
$config['allowed_types'] = 'jpeg|png|jpg';
$config['max_size'] = '10000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['file_name']='foto_ktp';
$config['overwrite'] = false;
$this->load->library('upload',$config);
$this->upload->do_upload('foto_ktp');
$upload_data = $this->upload->data();
$file_name = $upload_data['file_name'];
}
}
if($foto_laporan !== ""){
if(file_exists($upload_dir.$file_name1)){
show_error('file already exist');
}
else{
$config['upload_path'] = './assets/img/';
$config['allowed_types'] = 'jpeg|png|jpg';
$config['max_size'] = '10000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['file_name']='foto_laporan';
$config['overwrite'] = false;
$this->load->library('upload',$config);
$this->upload->do_upload('foto_laporan');
$upload_data = $this->upload->data();
$file_name1 = $a.$upload_data['file_name'];
}
}
$this->pelaporan->simpan_laporan($file_name,$file_name1,$foto_ktp,$foto_laporan);
redirect('pelaporan','refresh');
}
Model : M_pelaporan
class M_pelaporan extends CI_Model {
public function simpan_laporan($nama_file,$nama_file1)
{
if($nama_file==""){
$object = array(
'id_kasir'=>$this->session->userdata('id_kasir'),
'laporan'=>$this->input->post('laporan'),
'lok_laporan'=>$this->input->post('lok_laporan')
);
}else{
$object = array(
'id_kasir'=>$this->session->userdata('id_kasir'),
'laporan'=>$this->input->post('laporan'),
'foto_ktp'=>$nama_file,
'foto_laporan'=>$nama_file1,
'lok_laporan'=>$this->input->post('lok_laporan')
);
}
return $this->db->insert('laporan',$object);
}
View : pelaporan.php
<form action="<?=base_url('index.php/Pelaporan/tambah_laporan')?>" method="POST" enctype="multipart/form-data">
<table class="table">
<tr>
<td>Laporan</td>
<td><input type="text" name="laporan" class="form-control"><br>
</tr>
<tr>
<td>Foto KTP</td>
<td><input type="file" name="foto_ktp" class="file" multiple="true"><br>
</tr>
<tr>
<td>Foto laporan</td>
<td><input type="file" name="foto_laporan" class="file" multiple="true"><br>
</tr>
<tr>
<td>Lokasi laporan</td>
<td><input type="text" name="lok_laporan" class="form-control"><br>
</tr>
<tr>
<td><input type="submit" name="simpan" value="simpan" class="btn btn-success"></td>
</tr>
</table>
</form>
This code is upload 2 image but the first image named 'foto_ktp' is always replace with the previous uploaded photo it should sequence example foto_ktp1,foto_ktp2.The other input image named 'foto_pelaporan' can upload image but the name when uploaded is 'foto_ktp' that should named 'foto_laporan'and also with sequence number
codeigniter
add a comment |
up vote
0
down vote
favorite
image name in database only 'nama_ktp' and it must be two name, 1 is 'foto_ktp' and name 2 is 'foto_laporan'
Controller : Pelaporan.php
public function __construct()
{
parent::__construct();
$this->load->model('M_pelaporan','pelaporan');
}
public function index()
{
$data['konten']='pelaporan';
$this->load->view('template', $data);
}
public function tambah_laporan()
{
# code...
$foto_ktp = $_FILES['foto_ktp']['name'];
$foto_laporan = $_FILES['foto_laporan']['name'];
if($foto_ktp !== ""){
if(file_exists($upload_dir.$file_name)){
show_error('file already exist');
}
else{
$config['upload_path'] = './assets/img/';
$config['log_threshold'] = 1;
$config['allowed_types'] = 'jpeg|png|jpg';
$config['max_size'] = '10000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['file_name']='foto_ktp';
$config['overwrite'] = false;
$this->load->library('upload',$config);
$this->upload->do_upload('foto_ktp');
$upload_data = $this->upload->data();
$file_name = $upload_data['file_name'];
}
}
if($foto_laporan !== ""){
if(file_exists($upload_dir.$file_name1)){
show_error('file already exist');
}
else{
$config['upload_path'] = './assets/img/';
$config['allowed_types'] = 'jpeg|png|jpg';
$config['max_size'] = '10000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['file_name']='foto_laporan';
$config['overwrite'] = false;
$this->load->library('upload',$config);
$this->upload->do_upload('foto_laporan');
$upload_data = $this->upload->data();
$file_name1 = $a.$upload_data['file_name'];
}
}
$this->pelaporan->simpan_laporan($file_name,$file_name1,$foto_ktp,$foto_laporan);
redirect('pelaporan','refresh');
}
Model : M_pelaporan
class M_pelaporan extends CI_Model {
public function simpan_laporan($nama_file,$nama_file1)
{
if($nama_file==""){
$object = array(
'id_kasir'=>$this->session->userdata('id_kasir'),
'laporan'=>$this->input->post('laporan'),
'lok_laporan'=>$this->input->post('lok_laporan')
);
}else{
$object = array(
'id_kasir'=>$this->session->userdata('id_kasir'),
'laporan'=>$this->input->post('laporan'),
'foto_ktp'=>$nama_file,
'foto_laporan'=>$nama_file1,
'lok_laporan'=>$this->input->post('lok_laporan')
);
}
return $this->db->insert('laporan',$object);
}
View : pelaporan.php
<form action="<?=base_url('index.php/Pelaporan/tambah_laporan')?>" method="POST" enctype="multipart/form-data">
<table class="table">
<tr>
<td>Laporan</td>
<td><input type="text" name="laporan" class="form-control"><br>
</tr>
<tr>
<td>Foto KTP</td>
<td><input type="file" name="foto_ktp" class="file" multiple="true"><br>
</tr>
<tr>
<td>Foto laporan</td>
<td><input type="file" name="foto_laporan" class="file" multiple="true"><br>
</tr>
<tr>
<td>Lokasi laporan</td>
<td><input type="text" name="lok_laporan" class="form-control"><br>
</tr>
<tr>
<td><input type="submit" name="simpan" value="simpan" class="btn btn-success"></td>
</tr>
</table>
</form>
This code is upload 2 image but the first image named 'foto_ktp' is always replace with the previous uploaded photo it should sequence example foto_ktp1,foto_ktp2.The other input image named 'foto_pelaporan' can upload image but the name when uploaded is 'foto_ktp' that should named 'foto_laporan'and also with sequence number
codeigniter
what u do for the sequencing of file , i mean u have to do query with your db for the file name get file name then increment with +1 every time u upload the file
– pradeep
Jul 19 at 9:43
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
image name in database only 'nama_ktp' and it must be two name, 1 is 'foto_ktp' and name 2 is 'foto_laporan'
Controller : Pelaporan.php
public function __construct()
{
parent::__construct();
$this->load->model('M_pelaporan','pelaporan');
}
public function index()
{
$data['konten']='pelaporan';
$this->load->view('template', $data);
}
public function tambah_laporan()
{
# code...
$foto_ktp = $_FILES['foto_ktp']['name'];
$foto_laporan = $_FILES['foto_laporan']['name'];
if($foto_ktp !== ""){
if(file_exists($upload_dir.$file_name)){
show_error('file already exist');
}
else{
$config['upload_path'] = './assets/img/';
$config['log_threshold'] = 1;
$config['allowed_types'] = 'jpeg|png|jpg';
$config['max_size'] = '10000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['file_name']='foto_ktp';
$config['overwrite'] = false;
$this->load->library('upload',$config);
$this->upload->do_upload('foto_ktp');
$upload_data = $this->upload->data();
$file_name = $upload_data['file_name'];
}
}
if($foto_laporan !== ""){
if(file_exists($upload_dir.$file_name1)){
show_error('file already exist');
}
else{
$config['upload_path'] = './assets/img/';
$config['allowed_types'] = 'jpeg|png|jpg';
$config['max_size'] = '10000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['file_name']='foto_laporan';
$config['overwrite'] = false;
$this->load->library('upload',$config);
$this->upload->do_upload('foto_laporan');
$upload_data = $this->upload->data();
$file_name1 = $a.$upload_data['file_name'];
}
}
$this->pelaporan->simpan_laporan($file_name,$file_name1,$foto_ktp,$foto_laporan);
redirect('pelaporan','refresh');
}
Model : M_pelaporan
class M_pelaporan extends CI_Model {
public function simpan_laporan($nama_file,$nama_file1)
{
if($nama_file==""){
$object = array(
'id_kasir'=>$this->session->userdata('id_kasir'),
'laporan'=>$this->input->post('laporan'),
'lok_laporan'=>$this->input->post('lok_laporan')
);
}else{
$object = array(
'id_kasir'=>$this->session->userdata('id_kasir'),
'laporan'=>$this->input->post('laporan'),
'foto_ktp'=>$nama_file,
'foto_laporan'=>$nama_file1,
'lok_laporan'=>$this->input->post('lok_laporan')
);
}
return $this->db->insert('laporan',$object);
}
View : pelaporan.php
<form action="<?=base_url('index.php/Pelaporan/tambah_laporan')?>" method="POST" enctype="multipart/form-data">
<table class="table">
<tr>
<td>Laporan</td>
<td><input type="text" name="laporan" class="form-control"><br>
</tr>
<tr>
<td>Foto KTP</td>
<td><input type="file" name="foto_ktp" class="file" multiple="true"><br>
</tr>
<tr>
<td>Foto laporan</td>
<td><input type="file" name="foto_laporan" class="file" multiple="true"><br>
</tr>
<tr>
<td>Lokasi laporan</td>
<td><input type="text" name="lok_laporan" class="form-control"><br>
</tr>
<tr>
<td><input type="submit" name="simpan" value="simpan" class="btn btn-success"></td>
</tr>
</table>
</form>
This code is upload 2 image but the first image named 'foto_ktp' is always replace with the previous uploaded photo it should sequence example foto_ktp1,foto_ktp2.The other input image named 'foto_pelaporan' can upload image but the name when uploaded is 'foto_ktp' that should named 'foto_laporan'and also with sequence number
codeigniter
image name in database only 'nama_ktp' and it must be two name, 1 is 'foto_ktp' and name 2 is 'foto_laporan'
Controller : Pelaporan.php
public function __construct()
{
parent::__construct();
$this->load->model('M_pelaporan','pelaporan');
}
public function index()
{
$data['konten']='pelaporan';
$this->load->view('template', $data);
}
public function tambah_laporan()
{
# code...
$foto_ktp = $_FILES['foto_ktp']['name'];
$foto_laporan = $_FILES['foto_laporan']['name'];
if($foto_ktp !== ""){
if(file_exists($upload_dir.$file_name)){
show_error('file already exist');
}
else{
$config['upload_path'] = './assets/img/';
$config['log_threshold'] = 1;
$config['allowed_types'] = 'jpeg|png|jpg';
$config['max_size'] = '10000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['file_name']='foto_ktp';
$config['overwrite'] = false;
$this->load->library('upload',$config);
$this->upload->do_upload('foto_ktp');
$upload_data = $this->upload->data();
$file_name = $upload_data['file_name'];
}
}
if($foto_laporan !== ""){
if(file_exists($upload_dir.$file_name1)){
show_error('file already exist');
}
else{
$config['upload_path'] = './assets/img/';
$config['allowed_types'] = 'jpeg|png|jpg';
$config['max_size'] = '10000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['file_name']='foto_laporan';
$config['overwrite'] = false;
$this->load->library('upload',$config);
$this->upload->do_upload('foto_laporan');
$upload_data = $this->upload->data();
$file_name1 = $a.$upload_data['file_name'];
}
}
$this->pelaporan->simpan_laporan($file_name,$file_name1,$foto_ktp,$foto_laporan);
redirect('pelaporan','refresh');
}
Model : M_pelaporan
class M_pelaporan extends CI_Model {
public function simpan_laporan($nama_file,$nama_file1)
{
if($nama_file==""){
$object = array(
'id_kasir'=>$this->session->userdata('id_kasir'),
'laporan'=>$this->input->post('laporan'),
'lok_laporan'=>$this->input->post('lok_laporan')
);
}else{
$object = array(
'id_kasir'=>$this->session->userdata('id_kasir'),
'laporan'=>$this->input->post('laporan'),
'foto_ktp'=>$nama_file,
'foto_laporan'=>$nama_file1,
'lok_laporan'=>$this->input->post('lok_laporan')
);
}
return $this->db->insert('laporan',$object);
}
View : pelaporan.php
<form action="<?=base_url('index.php/Pelaporan/tambah_laporan')?>" method="POST" enctype="multipart/form-data">
<table class="table">
<tr>
<td>Laporan</td>
<td><input type="text" name="laporan" class="form-control"><br>
</tr>
<tr>
<td>Foto KTP</td>
<td><input type="file" name="foto_ktp" class="file" multiple="true"><br>
</tr>
<tr>
<td>Foto laporan</td>
<td><input type="file" name="foto_laporan" class="file" multiple="true"><br>
</tr>
<tr>
<td>Lokasi laporan</td>
<td><input type="text" name="lok_laporan" class="form-control"><br>
</tr>
<tr>
<td><input type="submit" name="simpan" value="simpan" class="btn btn-success"></td>
</tr>
</table>
</form>
This code is upload 2 image but the first image named 'foto_ktp' is always replace with the previous uploaded photo it should sequence example foto_ktp1,foto_ktp2.The other input image named 'foto_pelaporan' can upload image but the name when uploaded is 'foto_ktp' that should named 'foto_laporan'and also with sequence number
codeigniter
codeigniter
asked Jul 19 at 9:28
Ilham Maulana
1
1
what u do for the sequencing of file , i mean u have to do query with your db for the file name get file name then increment with +1 every time u upload the file
– pradeep
Jul 19 at 9:43
add a comment |
what u do for the sequencing of file , i mean u have to do query with your db for the file name get file name then increment with +1 every time u upload the file
– pradeep
Jul 19 at 9:43
what u do for the sequencing of file , i mean u have to do query with your db for the file name get file name then increment with +1 every time u upload the file
– pradeep
Jul 19 at 9:43
what u do for the sequencing of file , i mean u have to do query with your db for the file name get file name then increment with +1 every time u upload the file
– pradeep
Jul 19 at 9:43
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
edit this code.
$upload_data = $this->upload->data();
$file_name1 = $a.$upload_data['file_name'];
to
$upload_data2 = $this->upload->data();
$file_name1 = $upload_data2['file_name'];
add a comment |
up vote
0
down vote
Replace your method with this
public function tambah_laporan()
{
// Upload First Image -
$image_data1 = $this->uploadImage('foto_ktp');
$image1_name = isset($image_data1['file_name']) ? $image_data1['file_name'] : '';
// Upload Second Image - Same Conditions Applied As in the First Image
$image_data2 = $this->uploadImage('foto_laporan');
$image2_name= isset($image_data2['file_name']) ? $image_data2['file_name'] : '';
$this->pelaporan->simpan_laporan($image1_name,$image2_name);
redirect('pelaporan','refresh');
}
Add this method inside your Controller - This method is used to upload image it can also return image validation errors if you want to ..?
public function uploadImage($image_name)
{
$upload_dir = './assets/img/'; // directory path where your files/images are uploaded.
if($image_name !== ""){
if(file_exists($upload_dir.$image_name))
{
$data['error'] = 'Image Already Exists';
}
else
{
$config['upload_path'] = $upload_dir;
$config['allowed_types'] = 'jpeg|png|jpg';
$config['max_size'] = '10000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['file_name']= $image_name;
$config['overwrite'] = false;
$this->load->library('upload',$config);
if($this->upload->do_upload($image_name)) {
$upload_data = $this->upload->data();
$data['file_name'] = $upload_data['file_name'];
}else{
$upload_data = $this->upload->data();
$data['error'] = $this->upload->display_errors();
}
}
return $data;
}
}
Model - Replace this in your model.
class M_pelaporan extends CI_Model {
public function simpan_laporan($image_file1,$image_file2)
{
// You Don't Need Image Validation Here You Can do this in the Controller
$object = array(
'id_kasir'=>$this->session->userdata('id_kasir'),
'laporan'=>$this->input->post('laporan'),
'foto_ktp'=>$image_file1,
'foto_laporan'=>$image_file2,
'lok_laporan'=>$this->input->post('lok_laporan')
);
return $this->db->insert('laporan',$object);
}
}
undefined $upload_dir
– Ilham Maulana
Jul 20 at 3:36
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51419009%2fupload-two-images-in-codeigniter-but-one-of-them-is-replace-another-image%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
edit this code.
$upload_data = $this->upload->data();
$file_name1 = $a.$upload_data['file_name'];
to
$upload_data2 = $this->upload->data();
$file_name1 = $upload_data2['file_name'];
add a comment |
up vote
0
down vote
edit this code.
$upload_data = $this->upload->data();
$file_name1 = $a.$upload_data['file_name'];
to
$upload_data2 = $this->upload->data();
$file_name1 = $upload_data2['file_name'];
add a comment |
up vote
0
down vote
up vote
0
down vote
edit this code.
$upload_data = $this->upload->data();
$file_name1 = $a.$upload_data['file_name'];
to
$upload_data2 = $this->upload->data();
$file_name1 = $upload_data2['file_name'];
edit this code.
$upload_data = $this->upload->data();
$file_name1 = $a.$upload_data['file_name'];
to
$upload_data2 = $this->upload->data();
$file_name1 = $upload_data2['file_name'];
answered Jul 19 at 10:34
AbdulAhmad Matin
6891521
6891521
add a comment |
add a comment |
up vote
0
down vote
Replace your method with this
public function tambah_laporan()
{
// Upload First Image -
$image_data1 = $this->uploadImage('foto_ktp');
$image1_name = isset($image_data1['file_name']) ? $image_data1['file_name'] : '';
// Upload Second Image - Same Conditions Applied As in the First Image
$image_data2 = $this->uploadImage('foto_laporan');
$image2_name= isset($image_data2['file_name']) ? $image_data2['file_name'] : '';
$this->pelaporan->simpan_laporan($image1_name,$image2_name);
redirect('pelaporan','refresh');
}
Add this method inside your Controller - This method is used to upload image it can also return image validation errors if you want to ..?
public function uploadImage($image_name)
{
$upload_dir = './assets/img/'; // directory path where your files/images are uploaded.
if($image_name !== ""){
if(file_exists($upload_dir.$image_name))
{
$data['error'] = 'Image Already Exists';
}
else
{
$config['upload_path'] = $upload_dir;
$config['allowed_types'] = 'jpeg|png|jpg';
$config['max_size'] = '10000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['file_name']= $image_name;
$config['overwrite'] = false;
$this->load->library('upload',$config);
if($this->upload->do_upload($image_name)) {
$upload_data = $this->upload->data();
$data['file_name'] = $upload_data['file_name'];
}else{
$upload_data = $this->upload->data();
$data['error'] = $this->upload->display_errors();
}
}
return $data;
}
}
Model - Replace this in your model.
class M_pelaporan extends CI_Model {
public function simpan_laporan($image_file1,$image_file2)
{
// You Don't Need Image Validation Here You Can do this in the Controller
$object = array(
'id_kasir'=>$this->session->userdata('id_kasir'),
'laporan'=>$this->input->post('laporan'),
'foto_ktp'=>$image_file1,
'foto_laporan'=>$image_file2,
'lok_laporan'=>$this->input->post('lok_laporan')
);
return $this->db->insert('laporan',$object);
}
}
undefined $upload_dir
– Ilham Maulana
Jul 20 at 3:36
add a comment |
up vote
0
down vote
Replace your method with this
public function tambah_laporan()
{
// Upload First Image -
$image_data1 = $this->uploadImage('foto_ktp');
$image1_name = isset($image_data1['file_name']) ? $image_data1['file_name'] : '';
// Upload Second Image - Same Conditions Applied As in the First Image
$image_data2 = $this->uploadImage('foto_laporan');
$image2_name= isset($image_data2['file_name']) ? $image_data2['file_name'] : '';
$this->pelaporan->simpan_laporan($image1_name,$image2_name);
redirect('pelaporan','refresh');
}
Add this method inside your Controller - This method is used to upload image it can also return image validation errors if you want to ..?
public function uploadImage($image_name)
{
$upload_dir = './assets/img/'; // directory path where your files/images are uploaded.
if($image_name !== ""){
if(file_exists($upload_dir.$image_name))
{
$data['error'] = 'Image Already Exists';
}
else
{
$config['upload_path'] = $upload_dir;
$config['allowed_types'] = 'jpeg|png|jpg';
$config['max_size'] = '10000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['file_name']= $image_name;
$config['overwrite'] = false;
$this->load->library('upload',$config);
if($this->upload->do_upload($image_name)) {
$upload_data = $this->upload->data();
$data['file_name'] = $upload_data['file_name'];
}else{
$upload_data = $this->upload->data();
$data['error'] = $this->upload->display_errors();
}
}
return $data;
}
}
Model - Replace this in your model.
class M_pelaporan extends CI_Model {
public function simpan_laporan($image_file1,$image_file2)
{
// You Don't Need Image Validation Here You Can do this in the Controller
$object = array(
'id_kasir'=>$this->session->userdata('id_kasir'),
'laporan'=>$this->input->post('laporan'),
'foto_ktp'=>$image_file1,
'foto_laporan'=>$image_file2,
'lok_laporan'=>$this->input->post('lok_laporan')
);
return $this->db->insert('laporan',$object);
}
}
undefined $upload_dir
– Ilham Maulana
Jul 20 at 3:36
add a comment |
up vote
0
down vote
up vote
0
down vote
Replace your method with this
public function tambah_laporan()
{
// Upload First Image -
$image_data1 = $this->uploadImage('foto_ktp');
$image1_name = isset($image_data1['file_name']) ? $image_data1['file_name'] : '';
// Upload Second Image - Same Conditions Applied As in the First Image
$image_data2 = $this->uploadImage('foto_laporan');
$image2_name= isset($image_data2['file_name']) ? $image_data2['file_name'] : '';
$this->pelaporan->simpan_laporan($image1_name,$image2_name);
redirect('pelaporan','refresh');
}
Add this method inside your Controller - This method is used to upload image it can also return image validation errors if you want to ..?
public function uploadImage($image_name)
{
$upload_dir = './assets/img/'; // directory path where your files/images are uploaded.
if($image_name !== ""){
if(file_exists($upload_dir.$image_name))
{
$data['error'] = 'Image Already Exists';
}
else
{
$config['upload_path'] = $upload_dir;
$config['allowed_types'] = 'jpeg|png|jpg';
$config['max_size'] = '10000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['file_name']= $image_name;
$config['overwrite'] = false;
$this->load->library('upload',$config);
if($this->upload->do_upload($image_name)) {
$upload_data = $this->upload->data();
$data['file_name'] = $upload_data['file_name'];
}else{
$upload_data = $this->upload->data();
$data['error'] = $this->upload->display_errors();
}
}
return $data;
}
}
Model - Replace this in your model.
class M_pelaporan extends CI_Model {
public function simpan_laporan($image_file1,$image_file2)
{
// You Don't Need Image Validation Here You Can do this in the Controller
$object = array(
'id_kasir'=>$this->session->userdata('id_kasir'),
'laporan'=>$this->input->post('laporan'),
'foto_ktp'=>$image_file1,
'foto_laporan'=>$image_file2,
'lok_laporan'=>$this->input->post('lok_laporan')
);
return $this->db->insert('laporan',$object);
}
}
Replace your method with this
public function tambah_laporan()
{
// Upload First Image -
$image_data1 = $this->uploadImage('foto_ktp');
$image1_name = isset($image_data1['file_name']) ? $image_data1['file_name'] : '';
// Upload Second Image - Same Conditions Applied As in the First Image
$image_data2 = $this->uploadImage('foto_laporan');
$image2_name= isset($image_data2['file_name']) ? $image_data2['file_name'] : '';
$this->pelaporan->simpan_laporan($image1_name,$image2_name);
redirect('pelaporan','refresh');
}
Add this method inside your Controller - This method is used to upload image it can also return image validation errors if you want to ..?
public function uploadImage($image_name)
{
$upload_dir = './assets/img/'; // directory path where your files/images are uploaded.
if($image_name !== ""){
if(file_exists($upload_dir.$image_name))
{
$data['error'] = 'Image Already Exists';
}
else
{
$config['upload_path'] = $upload_dir;
$config['allowed_types'] = 'jpeg|png|jpg';
$config['max_size'] = '10000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['file_name']= $image_name;
$config['overwrite'] = false;
$this->load->library('upload',$config);
if($this->upload->do_upload($image_name)) {
$upload_data = $this->upload->data();
$data['file_name'] = $upload_data['file_name'];
}else{
$upload_data = $this->upload->data();
$data['error'] = $this->upload->display_errors();
}
}
return $data;
}
}
Model - Replace this in your model.
class M_pelaporan extends CI_Model {
public function simpan_laporan($image_file1,$image_file2)
{
// You Don't Need Image Validation Here You Can do this in the Controller
$object = array(
'id_kasir'=>$this->session->userdata('id_kasir'),
'laporan'=>$this->input->post('laporan'),
'foto_ktp'=>$image_file1,
'foto_laporan'=>$image_file2,
'lok_laporan'=>$this->input->post('lok_laporan')
);
return $this->db->insert('laporan',$object);
}
}
edited Nov 10 at 4:28
answered Jul 19 at 10:20
vishal kumar
155112
155112
undefined $upload_dir
– Ilham Maulana
Jul 20 at 3:36
add a comment |
undefined $upload_dir
– Ilham Maulana
Jul 20 at 3:36
undefined $upload_dir
– Ilham Maulana
Jul 20 at 3:36
undefined $upload_dir
– Ilham Maulana
Jul 20 at 3:36
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51419009%2fupload-two-images-in-codeigniter-but-one-of-them-is-replace-another-image%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
what u do for the sequencing of file , i mean u have to do query with your db for the file name get file name then increment with +1 every time u upload the file
– pradeep
Jul 19 at 9:43