how can fix error looping after rename file on codeigniter
I created a new function to change the name of the file to be uploaded. Now I have successfully changed the file name. but in my code, before it loops through the files normally it gives an error.
I have 5 files inputs where the input is in 1 form.
There was no problems before adding my function, but after adding the rename function, my loop became messy, but my old code was working correctly.
here is my old code:
public function proses_upload()
{
$gambar = array();
$jumlah = count($_FILES['userfile']['name']);
for ($i=0; $i < $jumlah; $i++)
{
$file_name = $_FILES['userfile']['name'][$i];
$tmp_name = $_FILES['userfile']['tmp_name'][$i];
move_uploaded_file($tmp_name, "file/".$file_name);
$gambar[$i] = $file_name;
}
$nama_file1 = $gambar[0];
$format_p2ptm =1;
$tanggal = date("Y-m-d H:i:s");
$jenis ='p2ptm';
$nama_file2 = $gambar[1];
$format_p2ptm2 =2;
$jenis ='p2ptm';
$nama_file3 = $gambar[2];
$format_p2ptm3 =3;
$jenis ='p2ptm';
$nama_file4 = $gambar[3];
$format_p2ptm4 =4;
$jenis ='p2ptm';
$nama_file5 = $gambar[4];
$format_p2ptm5 =5;
$jenis ='p2ptm';
if (!$nama_file1 == "") {
$this->app_model->insert_data('penyakit', $format_p2ptm, $tanggal,$nama_file1,$jenis, $this->session->userdata('id_puskesmas'));
}
if(!$nama_file2 == ""){
$this->app_model->insert_data('penyakit', $format_p2ptm2, $tanggal,$nama_file2,$jenis,$this->session->userdata('id_puskesmas'));
}
if(!$nama_file3 == ""){
$this->app_model->insert_data('penyakit', $format_p2ptm3, $tanggal,$nama_file3,$jenis,$this->session->userdata('id_puskesmas'));
}
if(!$nama_file4 == ""){
$this->app_model->insert_data('penyakit', $format_p2ptm4, $tanggal,$nama_file4,$jenis,$this->session->userdata('id_puskesmas'));
}
if(!$nama_file5 == ""){
$this->app_model->insert_data('penyakit', $format_p2ptm5, $tanggal,$nama_file5,$jenis,$this->session->userdata('id_puskesmas'));
}
redirect('puskesmas/view_puskesmas');
}
Here is my new code with errors:
public function proses_upload()
{
$gambar = array();
$jumlah = count($_FILES['userfile']['name']);
for ($i=0; $i < $jumlah; $i++)
{
$file_name = $_FILES['userfile']['name'][$i];
$explode = explode('.',$file_name);
// die(print_r($explode));
$ekstensi = pathinfo($file_name, PATHINFO_EXTENSION);
$bulan = date('M');
$tahun = date('y') ;
$kode = $this->session->userdata('kode_puskesmas');
$new_file_name = $explode[1].'_'.$kode.'_'.$bulan.$tahun.'.'.$ekstensi;
$tmp_name = $_FILES['userfile']['tmp_name'][$i];
move_uploaded_file($tmp_name, "file/".$new_file_name);
$gambar[$i] = $new_file_name;
}
$nama_file1 = $gambar[0];
$format_p2ptm =1;
$tanggal = date("Y-m-d H:i:s");
$jenis ='p2ptm';
$nama_file2 = $gambar[1];
$format_p2ptm2 =2;
$jenis ='p2ptm';
$nama_file3 = $gambar[2];
$format_p2ptm3 =3;
$jenis ='p2ptm';
$nama_file4 = $gambar[3];
$format_p2ptm4 =4;
$jenis ='p2ptm';
$nama_file5 = $gambar[4];
$format_p2ptm5 =5;
$jenis ='p2ptm';
if (!$nama_file1 == "") {
$this->app_model->insert_data('penyakit', $format_p2ptm, $tanggal,$nama_file1,$jenis, $this->session->userdata('id_puskesmas'));
}
if(!$nama_file2 == ""){
$this->app_model->insert_data('penyakit', $format_p2ptm2, $tanggal,$nama_file2,$jenis,$this->session->userdata('id_puskesmas'));
}
if(!$nama_file3 == ""){
$this->app_model->insert_data('penyakit', $format_p2ptm3, $tanggal,$nama_file3,$jenis,$this->session->userdata('id_puskesmas'));
}
if(!$nama_file4 == ""){
$this->app_model->insert_data('penyakit', $format_p2ptm4, $tanggal,$nama_file4,$jenis,$this->session->userdata('id_puskesmas'));
}
if(!$nama_file5 == ""){
$this->app_model->insert_data('penyakit', $format_p2ptm5, $tanggal,$nama_file5,$jenis,$this->session->userdata('id_puskesmas'));
}
redirect('puskesmas/view_puskesmas');
}
Here is my view form:
<?php echo form_open_multipart('puskesmas/proses_upload');?>
<br><br><br>
<p>
<h4>1. Form Lap PTM</h4>
</p>
<p>
<label>FORMAT : </label>
<input type="text" name="format" style="width:230px; height:25px; border:2; "
placeholder="Form Lap PTM" readonly>
</p>
<label >Input file : </label>
<input type="file" name="userfile">
<br><br><br>
<p>
<h4>2. Form Lap Posbindu</h4>
</p>
<p>
<label>FORMAT : </label>
<input type="text" name="format2" style="width:230px; height:25px; border:2; "
placeholder="Form Lap Posbindu " readonly =>
</p>
<label>Input file : </label>
<input type="file" name="userfile">
<br><br><br>
<p>
<h4>3. Form Lap IVA</h4>
</p>
<p>
<label>FORMAT : </label>
<input type="text" name="format3" style="width:230px; height:25px; border:2; "
placeholder="Form Lap IVA " readonly>
</p>
<label>Input file : </label>
<input type="file" name="userfile">
<br><br><br>
<p>
<h4>4. Form Lap Jiwa</h4>
</p>
<p>
<label>FORMAT : </label>
<input type="text" name="format4" style="width:230px; height:25px; border:2; "
placeholder="Form Lap Jiwa" readonly>
</p>
<label>Input file : </label>
<input type="file" name="userfile">
<br><br><br>
<p>
<h5>5. Form Lap Indera dan Gimul</h5>
</p>
<p>
<label>FORMAT : </label>
<input type="text" name="format5" style="width:230px; height:25px; border:2; "
placeholder="Form Lap Indera_dan Gimul" readonly>
</p>
<label>Input file : </label>
<input type="file" name="userfile">
<br><br><br>
<!-- <button class="" type="submit">Upload</button> -->
<input class="btn btn-primary btn-lg" type="submit" value="Upload">
<?php echo form_close() ?>
if I upload files one of the 5 inputs that for the column I fill in the input is true, but why do the remaining 4 other inputs also enter data? even though I only input 1 input
its my phpmyadmin foto input
php file codeigniter upload codeigniter-3
|
show 1 more comment
I created a new function to change the name of the file to be uploaded. Now I have successfully changed the file name. but in my code, before it loops through the files normally it gives an error.
I have 5 files inputs where the input is in 1 form.
There was no problems before adding my function, but after adding the rename function, my loop became messy, but my old code was working correctly.
here is my old code:
public function proses_upload()
{
$gambar = array();
$jumlah = count($_FILES['userfile']['name']);
for ($i=0; $i < $jumlah; $i++)
{
$file_name = $_FILES['userfile']['name'][$i];
$tmp_name = $_FILES['userfile']['tmp_name'][$i];
move_uploaded_file($tmp_name, "file/".$file_name);
$gambar[$i] = $file_name;
}
$nama_file1 = $gambar[0];
$format_p2ptm =1;
$tanggal = date("Y-m-d H:i:s");
$jenis ='p2ptm';
$nama_file2 = $gambar[1];
$format_p2ptm2 =2;
$jenis ='p2ptm';
$nama_file3 = $gambar[2];
$format_p2ptm3 =3;
$jenis ='p2ptm';
$nama_file4 = $gambar[3];
$format_p2ptm4 =4;
$jenis ='p2ptm';
$nama_file5 = $gambar[4];
$format_p2ptm5 =5;
$jenis ='p2ptm';
if (!$nama_file1 == "") {
$this->app_model->insert_data('penyakit', $format_p2ptm, $tanggal,$nama_file1,$jenis, $this->session->userdata('id_puskesmas'));
}
if(!$nama_file2 == ""){
$this->app_model->insert_data('penyakit', $format_p2ptm2, $tanggal,$nama_file2,$jenis,$this->session->userdata('id_puskesmas'));
}
if(!$nama_file3 == ""){
$this->app_model->insert_data('penyakit', $format_p2ptm3, $tanggal,$nama_file3,$jenis,$this->session->userdata('id_puskesmas'));
}
if(!$nama_file4 == ""){
$this->app_model->insert_data('penyakit', $format_p2ptm4, $tanggal,$nama_file4,$jenis,$this->session->userdata('id_puskesmas'));
}
if(!$nama_file5 == ""){
$this->app_model->insert_data('penyakit', $format_p2ptm5, $tanggal,$nama_file5,$jenis,$this->session->userdata('id_puskesmas'));
}
redirect('puskesmas/view_puskesmas');
}
Here is my new code with errors:
public function proses_upload()
{
$gambar = array();
$jumlah = count($_FILES['userfile']['name']);
for ($i=0; $i < $jumlah; $i++)
{
$file_name = $_FILES['userfile']['name'][$i];
$explode = explode('.',$file_name);
// die(print_r($explode));
$ekstensi = pathinfo($file_name, PATHINFO_EXTENSION);
$bulan = date('M');
$tahun = date('y') ;
$kode = $this->session->userdata('kode_puskesmas');
$new_file_name = $explode[1].'_'.$kode.'_'.$bulan.$tahun.'.'.$ekstensi;
$tmp_name = $_FILES['userfile']['tmp_name'][$i];
move_uploaded_file($tmp_name, "file/".$new_file_name);
$gambar[$i] = $new_file_name;
}
$nama_file1 = $gambar[0];
$format_p2ptm =1;
$tanggal = date("Y-m-d H:i:s");
$jenis ='p2ptm';
$nama_file2 = $gambar[1];
$format_p2ptm2 =2;
$jenis ='p2ptm';
$nama_file3 = $gambar[2];
$format_p2ptm3 =3;
$jenis ='p2ptm';
$nama_file4 = $gambar[3];
$format_p2ptm4 =4;
$jenis ='p2ptm';
$nama_file5 = $gambar[4];
$format_p2ptm5 =5;
$jenis ='p2ptm';
if (!$nama_file1 == "") {
$this->app_model->insert_data('penyakit', $format_p2ptm, $tanggal,$nama_file1,$jenis, $this->session->userdata('id_puskesmas'));
}
if(!$nama_file2 == ""){
$this->app_model->insert_data('penyakit', $format_p2ptm2, $tanggal,$nama_file2,$jenis,$this->session->userdata('id_puskesmas'));
}
if(!$nama_file3 == ""){
$this->app_model->insert_data('penyakit', $format_p2ptm3, $tanggal,$nama_file3,$jenis,$this->session->userdata('id_puskesmas'));
}
if(!$nama_file4 == ""){
$this->app_model->insert_data('penyakit', $format_p2ptm4, $tanggal,$nama_file4,$jenis,$this->session->userdata('id_puskesmas'));
}
if(!$nama_file5 == ""){
$this->app_model->insert_data('penyakit', $format_p2ptm5, $tanggal,$nama_file5,$jenis,$this->session->userdata('id_puskesmas'));
}
redirect('puskesmas/view_puskesmas');
}
Here is my view form:
<?php echo form_open_multipart('puskesmas/proses_upload');?>
<br><br><br>
<p>
<h4>1. Form Lap PTM</h4>
</p>
<p>
<label>FORMAT : </label>
<input type="text" name="format" style="width:230px; height:25px; border:2; "
placeholder="Form Lap PTM" readonly>
</p>
<label >Input file : </label>
<input type="file" name="userfile">
<br><br><br>
<p>
<h4>2. Form Lap Posbindu</h4>
</p>
<p>
<label>FORMAT : </label>
<input type="text" name="format2" style="width:230px; height:25px; border:2; "
placeholder="Form Lap Posbindu " readonly =>
</p>
<label>Input file : </label>
<input type="file" name="userfile">
<br><br><br>
<p>
<h4>3. Form Lap IVA</h4>
</p>
<p>
<label>FORMAT : </label>
<input type="text" name="format3" style="width:230px; height:25px; border:2; "
placeholder="Form Lap IVA " readonly>
</p>
<label>Input file : </label>
<input type="file" name="userfile">
<br><br><br>
<p>
<h4>4. Form Lap Jiwa</h4>
</p>
<p>
<label>FORMAT : </label>
<input type="text" name="format4" style="width:230px; height:25px; border:2; "
placeholder="Form Lap Jiwa" readonly>
</p>
<label>Input file : </label>
<input type="file" name="userfile">
<br><br><br>
<p>
<h5>5. Form Lap Indera dan Gimul</h5>
</p>
<p>
<label>FORMAT : </label>
<input type="text" name="format5" style="width:230px; height:25px; border:2; "
placeholder="Form Lap Indera_dan Gimul" readonly>
</p>
<label>Input file : </label>
<input type="file" name="userfile">
<br><br><br>
<!-- <button class="" type="submit">Upload</button> -->
<input class="btn btn-primary btn-lg" type="submit" value="Upload">
<?php echo form_close() ?>
if I upload files one of the 5 inputs that for the column I fill in the input is true, but why do the remaining 4 other inputs also enter data? even though I only input 1 input
its my phpmyadmin foto input
php file codeigniter upload codeigniter-3
@10200840 Can you make a var_dump of $new_file_name?
– EvE
Jan 1 at 3:08
Form Lap PTM_KDW2_Jan19.xlsx1 . i using die(print_r($new_file_name));
– Adhik Mulat
Jan 1 at 3:17
this looping is failed and i didnt know where i can take [$i]
– Adhik Mulat
Jan 1 at 3:17
you can see the picture at under thread
– Adhik Mulat
Jan 1 at 3:18
they are being added because you are assigning them a value specifically this line: $gambar[$i] = $new_file_name;
– Second2None
Jan 1 at 3:19
|
show 1 more comment
I created a new function to change the name of the file to be uploaded. Now I have successfully changed the file name. but in my code, before it loops through the files normally it gives an error.
I have 5 files inputs where the input is in 1 form.
There was no problems before adding my function, but after adding the rename function, my loop became messy, but my old code was working correctly.
here is my old code:
public function proses_upload()
{
$gambar = array();
$jumlah = count($_FILES['userfile']['name']);
for ($i=0; $i < $jumlah; $i++)
{
$file_name = $_FILES['userfile']['name'][$i];
$tmp_name = $_FILES['userfile']['tmp_name'][$i];
move_uploaded_file($tmp_name, "file/".$file_name);
$gambar[$i] = $file_name;
}
$nama_file1 = $gambar[0];
$format_p2ptm =1;
$tanggal = date("Y-m-d H:i:s");
$jenis ='p2ptm';
$nama_file2 = $gambar[1];
$format_p2ptm2 =2;
$jenis ='p2ptm';
$nama_file3 = $gambar[2];
$format_p2ptm3 =3;
$jenis ='p2ptm';
$nama_file4 = $gambar[3];
$format_p2ptm4 =4;
$jenis ='p2ptm';
$nama_file5 = $gambar[4];
$format_p2ptm5 =5;
$jenis ='p2ptm';
if (!$nama_file1 == "") {
$this->app_model->insert_data('penyakit', $format_p2ptm, $tanggal,$nama_file1,$jenis, $this->session->userdata('id_puskesmas'));
}
if(!$nama_file2 == ""){
$this->app_model->insert_data('penyakit', $format_p2ptm2, $tanggal,$nama_file2,$jenis,$this->session->userdata('id_puskesmas'));
}
if(!$nama_file3 == ""){
$this->app_model->insert_data('penyakit', $format_p2ptm3, $tanggal,$nama_file3,$jenis,$this->session->userdata('id_puskesmas'));
}
if(!$nama_file4 == ""){
$this->app_model->insert_data('penyakit', $format_p2ptm4, $tanggal,$nama_file4,$jenis,$this->session->userdata('id_puskesmas'));
}
if(!$nama_file5 == ""){
$this->app_model->insert_data('penyakit', $format_p2ptm5, $tanggal,$nama_file5,$jenis,$this->session->userdata('id_puskesmas'));
}
redirect('puskesmas/view_puskesmas');
}
Here is my new code with errors:
public function proses_upload()
{
$gambar = array();
$jumlah = count($_FILES['userfile']['name']);
for ($i=0; $i < $jumlah; $i++)
{
$file_name = $_FILES['userfile']['name'][$i];
$explode = explode('.',$file_name);
// die(print_r($explode));
$ekstensi = pathinfo($file_name, PATHINFO_EXTENSION);
$bulan = date('M');
$tahun = date('y') ;
$kode = $this->session->userdata('kode_puskesmas');
$new_file_name = $explode[1].'_'.$kode.'_'.$bulan.$tahun.'.'.$ekstensi;
$tmp_name = $_FILES['userfile']['tmp_name'][$i];
move_uploaded_file($tmp_name, "file/".$new_file_name);
$gambar[$i] = $new_file_name;
}
$nama_file1 = $gambar[0];
$format_p2ptm =1;
$tanggal = date("Y-m-d H:i:s");
$jenis ='p2ptm';
$nama_file2 = $gambar[1];
$format_p2ptm2 =2;
$jenis ='p2ptm';
$nama_file3 = $gambar[2];
$format_p2ptm3 =3;
$jenis ='p2ptm';
$nama_file4 = $gambar[3];
$format_p2ptm4 =4;
$jenis ='p2ptm';
$nama_file5 = $gambar[4];
$format_p2ptm5 =5;
$jenis ='p2ptm';
if (!$nama_file1 == "") {
$this->app_model->insert_data('penyakit', $format_p2ptm, $tanggal,$nama_file1,$jenis, $this->session->userdata('id_puskesmas'));
}
if(!$nama_file2 == ""){
$this->app_model->insert_data('penyakit', $format_p2ptm2, $tanggal,$nama_file2,$jenis,$this->session->userdata('id_puskesmas'));
}
if(!$nama_file3 == ""){
$this->app_model->insert_data('penyakit', $format_p2ptm3, $tanggal,$nama_file3,$jenis,$this->session->userdata('id_puskesmas'));
}
if(!$nama_file4 == ""){
$this->app_model->insert_data('penyakit', $format_p2ptm4, $tanggal,$nama_file4,$jenis,$this->session->userdata('id_puskesmas'));
}
if(!$nama_file5 == ""){
$this->app_model->insert_data('penyakit', $format_p2ptm5, $tanggal,$nama_file5,$jenis,$this->session->userdata('id_puskesmas'));
}
redirect('puskesmas/view_puskesmas');
}
Here is my view form:
<?php echo form_open_multipart('puskesmas/proses_upload');?>
<br><br><br>
<p>
<h4>1. Form Lap PTM</h4>
</p>
<p>
<label>FORMAT : </label>
<input type="text" name="format" style="width:230px; height:25px; border:2; "
placeholder="Form Lap PTM" readonly>
</p>
<label >Input file : </label>
<input type="file" name="userfile">
<br><br><br>
<p>
<h4>2. Form Lap Posbindu</h4>
</p>
<p>
<label>FORMAT : </label>
<input type="text" name="format2" style="width:230px; height:25px; border:2; "
placeholder="Form Lap Posbindu " readonly =>
</p>
<label>Input file : </label>
<input type="file" name="userfile">
<br><br><br>
<p>
<h4>3. Form Lap IVA</h4>
</p>
<p>
<label>FORMAT : </label>
<input type="text" name="format3" style="width:230px; height:25px; border:2; "
placeholder="Form Lap IVA " readonly>
</p>
<label>Input file : </label>
<input type="file" name="userfile">
<br><br><br>
<p>
<h4>4. Form Lap Jiwa</h4>
</p>
<p>
<label>FORMAT : </label>
<input type="text" name="format4" style="width:230px; height:25px; border:2; "
placeholder="Form Lap Jiwa" readonly>
</p>
<label>Input file : </label>
<input type="file" name="userfile">
<br><br><br>
<p>
<h5>5. Form Lap Indera dan Gimul</h5>
</p>
<p>
<label>FORMAT : </label>
<input type="text" name="format5" style="width:230px; height:25px; border:2; "
placeholder="Form Lap Indera_dan Gimul" readonly>
</p>
<label>Input file : </label>
<input type="file" name="userfile">
<br><br><br>
<!-- <button class="" type="submit">Upload</button> -->
<input class="btn btn-primary btn-lg" type="submit" value="Upload">
<?php echo form_close() ?>
if I upload files one of the 5 inputs that for the column I fill in the input is true, but why do the remaining 4 other inputs also enter data? even though I only input 1 input
its my phpmyadmin foto input
php file codeigniter upload codeigniter-3
I created a new function to change the name of the file to be uploaded. Now I have successfully changed the file name. but in my code, before it loops through the files normally it gives an error.
I have 5 files inputs where the input is in 1 form.
There was no problems before adding my function, but after adding the rename function, my loop became messy, but my old code was working correctly.
here is my old code:
public function proses_upload()
{
$gambar = array();
$jumlah = count($_FILES['userfile']['name']);
for ($i=0; $i < $jumlah; $i++)
{
$file_name = $_FILES['userfile']['name'][$i];
$tmp_name = $_FILES['userfile']['tmp_name'][$i];
move_uploaded_file($tmp_name, "file/".$file_name);
$gambar[$i] = $file_name;
}
$nama_file1 = $gambar[0];
$format_p2ptm =1;
$tanggal = date("Y-m-d H:i:s");
$jenis ='p2ptm';
$nama_file2 = $gambar[1];
$format_p2ptm2 =2;
$jenis ='p2ptm';
$nama_file3 = $gambar[2];
$format_p2ptm3 =3;
$jenis ='p2ptm';
$nama_file4 = $gambar[3];
$format_p2ptm4 =4;
$jenis ='p2ptm';
$nama_file5 = $gambar[4];
$format_p2ptm5 =5;
$jenis ='p2ptm';
if (!$nama_file1 == "") {
$this->app_model->insert_data('penyakit', $format_p2ptm, $tanggal,$nama_file1,$jenis, $this->session->userdata('id_puskesmas'));
}
if(!$nama_file2 == ""){
$this->app_model->insert_data('penyakit', $format_p2ptm2, $tanggal,$nama_file2,$jenis,$this->session->userdata('id_puskesmas'));
}
if(!$nama_file3 == ""){
$this->app_model->insert_data('penyakit', $format_p2ptm3, $tanggal,$nama_file3,$jenis,$this->session->userdata('id_puskesmas'));
}
if(!$nama_file4 == ""){
$this->app_model->insert_data('penyakit', $format_p2ptm4, $tanggal,$nama_file4,$jenis,$this->session->userdata('id_puskesmas'));
}
if(!$nama_file5 == ""){
$this->app_model->insert_data('penyakit', $format_p2ptm5, $tanggal,$nama_file5,$jenis,$this->session->userdata('id_puskesmas'));
}
redirect('puskesmas/view_puskesmas');
}
Here is my new code with errors:
public function proses_upload()
{
$gambar = array();
$jumlah = count($_FILES['userfile']['name']);
for ($i=0; $i < $jumlah; $i++)
{
$file_name = $_FILES['userfile']['name'][$i];
$explode = explode('.',$file_name);
// die(print_r($explode));
$ekstensi = pathinfo($file_name, PATHINFO_EXTENSION);
$bulan = date('M');
$tahun = date('y') ;
$kode = $this->session->userdata('kode_puskesmas');
$new_file_name = $explode[1].'_'.$kode.'_'.$bulan.$tahun.'.'.$ekstensi;
$tmp_name = $_FILES['userfile']['tmp_name'][$i];
move_uploaded_file($tmp_name, "file/".$new_file_name);
$gambar[$i] = $new_file_name;
}
$nama_file1 = $gambar[0];
$format_p2ptm =1;
$tanggal = date("Y-m-d H:i:s");
$jenis ='p2ptm';
$nama_file2 = $gambar[1];
$format_p2ptm2 =2;
$jenis ='p2ptm';
$nama_file3 = $gambar[2];
$format_p2ptm3 =3;
$jenis ='p2ptm';
$nama_file4 = $gambar[3];
$format_p2ptm4 =4;
$jenis ='p2ptm';
$nama_file5 = $gambar[4];
$format_p2ptm5 =5;
$jenis ='p2ptm';
if (!$nama_file1 == "") {
$this->app_model->insert_data('penyakit', $format_p2ptm, $tanggal,$nama_file1,$jenis, $this->session->userdata('id_puskesmas'));
}
if(!$nama_file2 == ""){
$this->app_model->insert_data('penyakit', $format_p2ptm2, $tanggal,$nama_file2,$jenis,$this->session->userdata('id_puskesmas'));
}
if(!$nama_file3 == ""){
$this->app_model->insert_data('penyakit', $format_p2ptm3, $tanggal,$nama_file3,$jenis,$this->session->userdata('id_puskesmas'));
}
if(!$nama_file4 == ""){
$this->app_model->insert_data('penyakit', $format_p2ptm4, $tanggal,$nama_file4,$jenis,$this->session->userdata('id_puskesmas'));
}
if(!$nama_file5 == ""){
$this->app_model->insert_data('penyakit', $format_p2ptm5, $tanggal,$nama_file5,$jenis,$this->session->userdata('id_puskesmas'));
}
redirect('puskesmas/view_puskesmas');
}
Here is my view form:
<?php echo form_open_multipart('puskesmas/proses_upload');?>
<br><br><br>
<p>
<h4>1. Form Lap PTM</h4>
</p>
<p>
<label>FORMAT : </label>
<input type="text" name="format" style="width:230px; height:25px; border:2; "
placeholder="Form Lap PTM" readonly>
</p>
<label >Input file : </label>
<input type="file" name="userfile">
<br><br><br>
<p>
<h4>2. Form Lap Posbindu</h4>
</p>
<p>
<label>FORMAT : </label>
<input type="text" name="format2" style="width:230px; height:25px; border:2; "
placeholder="Form Lap Posbindu " readonly =>
</p>
<label>Input file : </label>
<input type="file" name="userfile">
<br><br><br>
<p>
<h4>3. Form Lap IVA</h4>
</p>
<p>
<label>FORMAT : </label>
<input type="text" name="format3" style="width:230px; height:25px; border:2; "
placeholder="Form Lap IVA " readonly>
</p>
<label>Input file : </label>
<input type="file" name="userfile">
<br><br><br>
<p>
<h4>4. Form Lap Jiwa</h4>
</p>
<p>
<label>FORMAT : </label>
<input type="text" name="format4" style="width:230px; height:25px; border:2; "
placeholder="Form Lap Jiwa" readonly>
</p>
<label>Input file : </label>
<input type="file" name="userfile">
<br><br><br>
<p>
<h5>5. Form Lap Indera dan Gimul</h5>
</p>
<p>
<label>FORMAT : </label>
<input type="text" name="format5" style="width:230px; height:25px; border:2; "
placeholder="Form Lap Indera_dan Gimul" readonly>
</p>
<label>Input file : </label>
<input type="file" name="userfile">
<br><br><br>
<!-- <button class="" type="submit">Upload</button> -->
<input class="btn btn-primary btn-lg" type="submit" value="Upload">
<?php echo form_close() ?>
if I upload files one of the 5 inputs that for the column I fill in the input is true, but why do the remaining 4 other inputs also enter data? even though I only input 1 input
its my phpmyadmin foto input
php file codeigniter upload codeigniter-3
php file codeigniter upload codeigniter-3
edited Jan 1 at 2:53
user10850918
336
336
asked Jan 1 at 1:56
Adhik MulatAdhik Mulat
55
55
@10200840 Can you make a var_dump of $new_file_name?
– EvE
Jan 1 at 3:08
Form Lap PTM_KDW2_Jan19.xlsx1 . i using die(print_r($new_file_name));
– Adhik Mulat
Jan 1 at 3:17
this looping is failed and i didnt know where i can take [$i]
– Adhik Mulat
Jan 1 at 3:17
you can see the picture at under thread
– Adhik Mulat
Jan 1 at 3:18
they are being added because you are assigning them a value specifically this line: $gambar[$i] = $new_file_name;
– Second2None
Jan 1 at 3:19
|
show 1 more comment
@10200840 Can you make a var_dump of $new_file_name?
– EvE
Jan 1 at 3:08
Form Lap PTM_KDW2_Jan19.xlsx1 . i using die(print_r($new_file_name));
– Adhik Mulat
Jan 1 at 3:17
this looping is failed and i didnt know where i can take [$i]
– Adhik Mulat
Jan 1 at 3:17
you can see the picture at under thread
– Adhik Mulat
Jan 1 at 3:18
they are being added because you are assigning them a value specifically this line: $gambar[$i] = $new_file_name;
– Second2None
Jan 1 at 3:19
@10200840 Can you make a var_dump of $new_file_name?
– EvE
Jan 1 at 3:08
@10200840 Can you make a var_dump of $new_file_name?
– EvE
Jan 1 at 3:08
Form Lap PTM_KDW2_Jan19.xlsx1 . i using die(print_r($new_file_name));
– Adhik Mulat
Jan 1 at 3:17
Form Lap PTM_KDW2_Jan19.xlsx1 . i using die(print_r($new_file_name));
– Adhik Mulat
Jan 1 at 3:17
this looping is failed and i didnt know where i can take [$i]
– Adhik Mulat
Jan 1 at 3:17
this looping is failed and i didnt know where i can take [$i]
– Adhik Mulat
Jan 1 at 3:17
you can see the picture at under thread
– Adhik Mulat
Jan 1 at 3:18
you can see the picture at under thread
– Adhik Mulat
Jan 1 at 3:18
they are being added because you are assigning them a value specifically this line: $gambar[$i] = $new_file_name;
– Second2None
Jan 1 at 3:19
they are being added because you are assigning them a value specifically this line: $gambar[$i] = $new_file_name;
– Second2None
Jan 1 at 3:19
|
show 1 more comment
1 Answer
1
active
oldest
votes
There will always be 5 files sent due to 5 inputs being sent, you need to verify whether or not they are empty or filled.
$jumlah = count(array_filter($_FILES['userfile']['name']));
Will give you the true count value of how many files have been uploaded, removing the blanks. You would ther need to update the rest of your code to accommodate for there only being x amount of array values.
To keep your current code with minimal changes you can add an if statement to check if the name is blank
$file_name = $_FILES['userfile']['name'][$i];
$gambar[$i] = ''; //set it to blank by default for your checks further down
if($file_name != ''){
$explode = explode('.',$file_name);
// die(print_r($explode));
$ekstensi = pathinfo($file_name, PATHINFO_EXTENSION);
$bulan = date('M');
$tahun = date('y') ;
$kode = $this->session->userdata('kode_puskesmas');
$new_file_name = $explode[1].'_'.$kode.'_'.$bulan.$tahun.'.'.$ekstensi;
$tmp_name = $_FILES['userfile']['tmp_name'][$i];
move_uploaded_file($tmp_name, "file/".$new_file_name);
$gambar[$i] = $new_file_name;
}
i dont know what happen but its error again . its just can input on input tag first (on top)
– Adhik Mulat
Jan 1 at 14:04
You need to either update your code with an edit so we know what changes you made, or start a new question if you are getting a different error.
– Second2None
Jan 2 at 0:20
ok can you help me again ? i will share my new question here
– Adhik Mulat
Jan 2 at 2:00
here
– Adhik Mulat
Jan 2 at 2:14
See the part where I said "To keep your current code with minimal changes you can add an if statement to check if the name is blank" I didn't say you need to make both changes. You have literally added both fixes.
– Second2None
Jan 2 at 2:23
|
show 2 more comments
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',
autoActivateHeartbeat: false,
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%2f53992589%2fhow-can-fix-error-looping-after-rename-file-on-codeigniter%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
There will always be 5 files sent due to 5 inputs being sent, you need to verify whether or not they are empty or filled.
$jumlah = count(array_filter($_FILES['userfile']['name']));
Will give you the true count value of how many files have been uploaded, removing the blanks. You would ther need to update the rest of your code to accommodate for there only being x amount of array values.
To keep your current code with minimal changes you can add an if statement to check if the name is blank
$file_name = $_FILES['userfile']['name'][$i];
$gambar[$i] = ''; //set it to blank by default for your checks further down
if($file_name != ''){
$explode = explode('.',$file_name);
// die(print_r($explode));
$ekstensi = pathinfo($file_name, PATHINFO_EXTENSION);
$bulan = date('M');
$tahun = date('y') ;
$kode = $this->session->userdata('kode_puskesmas');
$new_file_name = $explode[1].'_'.$kode.'_'.$bulan.$tahun.'.'.$ekstensi;
$tmp_name = $_FILES['userfile']['tmp_name'][$i];
move_uploaded_file($tmp_name, "file/".$new_file_name);
$gambar[$i] = $new_file_name;
}
i dont know what happen but its error again . its just can input on input tag first (on top)
– Adhik Mulat
Jan 1 at 14:04
You need to either update your code with an edit so we know what changes you made, or start a new question if you are getting a different error.
– Second2None
Jan 2 at 0:20
ok can you help me again ? i will share my new question here
– Adhik Mulat
Jan 2 at 2:00
here
– Adhik Mulat
Jan 2 at 2:14
See the part where I said "To keep your current code with minimal changes you can add an if statement to check if the name is blank" I didn't say you need to make both changes. You have literally added both fixes.
– Second2None
Jan 2 at 2:23
|
show 2 more comments
There will always be 5 files sent due to 5 inputs being sent, you need to verify whether or not they are empty or filled.
$jumlah = count(array_filter($_FILES['userfile']['name']));
Will give you the true count value of how many files have been uploaded, removing the blanks. You would ther need to update the rest of your code to accommodate for there only being x amount of array values.
To keep your current code with minimal changes you can add an if statement to check if the name is blank
$file_name = $_FILES['userfile']['name'][$i];
$gambar[$i] = ''; //set it to blank by default for your checks further down
if($file_name != ''){
$explode = explode('.',$file_name);
// die(print_r($explode));
$ekstensi = pathinfo($file_name, PATHINFO_EXTENSION);
$bulan = date('M');
$tahun = date('y') ;
$kode = $this->session->userdata('kode_puskesmas');
$new_file_name = $explode[1].'_'.$kode.'_'.$bulan.$tahun.'.'.$ekstensi;
$tmp_name = $_FILES['userfile']['tmp_name'][$i];
move_uploaded_file($tmp_name, "file/".$new_file_name);
$gambar[$i] = $new_file_name;
}
i dont know what happen but its error again . its just can input on input tag first (on top)
– Adhik Mulat
Jan 1 at 14:04
You need to either update your code with an edit so we know what changes you made, or start a new question if you are getting a different error.
– Second2None
Jan 2 at 0:20
ok can you help me again ? i will share my new question here
– Adhik Mulat
Jan 2 at 2:00
here
– Adhik Mulat
Jan 2 at 2:14
See the part where I said "To keep your current code with minimal changes you can add an if statement to check if the name is blank" I didn't say you need to make both changes. You have literally added both fixes.
– Second2None
Jan 2 at 2:23
|
show 2 more comments
There will always be 5 files sent due to 5 inputs being sent, you need to verify whether or not they are empty or filled.
$jumlah = count(array_filter($_FILES['userfile']['name']));
Will give you the true count value of how many files have been uploaded, removing the blanks. You would ther need to update the rest of your code to accommodate for there only being x amount of array values.
To keep your current code with minimal changes you can add an if statement to check if the name is blank
$file_name = $_FILES['userfile']['name'][$i];
$gambar[$i] = ''; //set it to blank by default for your checks further down
if($file_name != ''){
$explode = explode('.',$file_name);
// die(print_r($explode));
$ekstensi = pathinfo($file_name, PATHINFO_EXTENSION);
$bulan = date('M');
$tahun = date('y') ;
$kode = $this->session->userdata('kode_puskesmas');
$new_file_name = $explode[1].'_'.$kode.'_'.$bulan.$tahun.'.'.$ekstensi;
$tmp_name = $_FILES['userfile']['tmp_name'][$i];
move_uploaded_file($tmp_name, "file/".$new_file_name);
$gambar[$i] = $new_file_name;
}
There will always be 5 files sent due to 5 inputs being sent, you need to verify whether or not they are empty or filled.
$jumlah = count(array_filter($_FILES['userfile']['name']));
Will give you the true count value of how many files have been uploaded, removing the blanks. You would ther need to update the rest of your code to accommodate for there only being x amount of array values.
To keep your current code with minimal changes you can add an if statement to check if the name is blank
$file_name = $_FILES['userfile']['name'][$i];
$gambar[$i] = ''; //set it to blank by default for your checks further down
if($file_name != ''){
$explode = explode('.',$file_name);
// die(print_r($explode));
$ekstensi = pathinfo($file_name, PATHINFO_EXTENSION);
$bulan = date('M');
$tahun = date('y') ;
$kode = $this->session->userdata('kode_puskesmas');
$new_file_name = $explode[1].'_'.$kode.'_'.$bulan.$tahun.'.'.$ekstensi;
$tmp_name = $_FILES['userfile']['tmp_name'][$i];
move_uploaded_file($tmp_name, "file/".$new_file_name);
$gambar[$i] = $new_file_name;
}
answered Jan 1 at 3:16
Second2NoneSecond2None
1,0681215
1,0681215
i dont know what happen but its error again . its just can input on input tag first (on top)
– Adhik Mulat
Jan 1 at 14:04
You need to either update your code with an edit so we know what changes you made, or start a new question if you are getting a different error.
– Second2None
Jan 2 at 0:20
ok can you help me again ? i will share my new question here
– Adhik Mulat
Jan 2 at 2:00
here
– Adhik Mulat
Jan 2 at 2:14
See the part where I said "To keep your current code with minimal changes you can add an if statement to check if the name is blank" I didn't say you need to make both changes. You have literally added both fixes.
– Second2None
Jan 2 at 2:23
|
show 2 more comments
i dont know what happen but its error again . its just can input on input tag first (on top)
– Adhik Mulat
Jan 1 at 14:04
You need to either update your code with an edit so we know what changes you made, or start a new question if you are getting a different error.
– Second2None
Jan 2 at 0:20
ok can you help me again ? i will share my new question here
– Adhik Mulat
Jan 2 at 2:00
here
– Adhik Mulat
Jan 2 at 2:14
See the part where I said "To keep your current code with minimal changes you can add an if statement to check if the name is blank" I didn't say you need to make both changes. You have literally added both fixes.
– Second2None
Jan 2 at 2:23
i dont know what happen but its error again . its just can input on input tag first (on top)
– Adhik Mulat
Jan 1 at 14:04
i dont know what happen but its error again . its just can input on input tag first (on top)
– Adhik Mulat
Jan 1 at 14:04
You need to either update your code with an edit so we know what changes you made, or start a new question if you are getting a different error.
– Second2None
Jan 2 at 0:20
You need to either update your code with an edit so we know what changes you made, or start a new question if you are getting a different error.
– Second2None
Jan 2 at 0:20
ok can you help me again ? i will share my new question here
– Adhik Mulat
Jan 2 at 2:00
ok can you help me again ? i will share my new question here
– Adhik Mulat
Jan 2 at 2:00
here
– Adhik Mulat
Jan 2 at 2:14
here
– Adhik Mulat
Jan 2 at 2:14
See the part where I said "To keep your current code with minimal changes you can add an if statement to check if the name is blank" I didn't say you need to make both changes. You have literally added both fixes.
– Second2None
Jan 2 at 2:23
See the part where I said "To keep your current code with minimal changes you can add an if statement to check if the name is blank" I didn't say you need to make both changes. You have literally added both fixes.
– Second2None
Jan 2 at 2:23
|
show 2 more comments
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.
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%2f53992589%2fhow-can-fix-error-looping-after-rename-file-on-codeigniter%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
@10200840 Can you make a var_dump of $new_file_name?
– EvE
Jan 1 at 3:08
Form Lap PTM_KDW2_Jan19.xlsx1 . i using die(print_r($new_file_name));
– Adhik Mulat
Jan 1 at 3:17
this looping is failed and i didnt know where i can take [$i]
– Adhik Mulat
Jan 1 at 3:17
you can see the picture at under thread
– Adhik Mulat
Jan 1 at 3:18
they are being added because you are assigning them a value specifically this line: $gambar[$i] = $new_file_name;
– Second2None
Jan 1 at 3:19