cara upload 2 gambar sekaligus di php mysqli

asslamu alaikum.... perkenalkan nama saya DICKIE CHANS alamat saya dari subang, jawa barat. untuk menanyakan tentang cara upload gambar ditambahkan menjadi upload 2 gambar sekaligus gimana ya kak ?

avatar DickyChans58
@DickyChans58

4 Kontribusi 0 Poin

Dipost 3 tahun yang lalu

3 Jawaban:

<pre>&lt;section class="content-header"&gt; &lt;h1&gt; Keanggotaan &lt;small&gt;Kartu Tanda Anggota&lt;/small&gt; &lt;/h1&gt; &lt;ol class="breadcrumb"&gt; &lt;li&gt;&lt;a href="#"&gt;&lt;i class="fa fa-dashboard"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/li&gt; &lt;li class="active"&gt;Kartu Tanda Anggota&lt;/li&gt; &lt;/ol&gt; &lt;/section&gt; &lt;section class="content"&gt; &lt;div class="row"&gt; &lt;div class="col-xs-12"&gt; &lt;div class="box box-danger"&gt; &lt;div class="box-header"&gt; &lt;h3 class="box-title"&gt;Tambah Kartu Tanda Anggota&lt;/h3&gt; &lt;div class="pull-right"&gt; &lt;a href="?page=KTA" class="btn btn-warning btn-sm"&gt; &lt;i class="fa fa-undo"&gt;&lt;/i&gt; Kembali &lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="box-body"&gt; &lt;div class="row"&gt; &lt;div class="col-xs-4 col-xs-offset-4"&gt; &lt;?php $carikode = mysqli_query($conn, "SELECT max(kode_reg) FROM tb_kta") or die (mysqli_error()); $datakode = mysqli_fetch_array($carikode); if($datakode) { $nilaikode = substr($datakode[0], 11); $kode = (int) $nilaikode; $kode = $kode + 1; $hasilkode = "62.10.3213.".str_pad($kode, 4, "0", STR_PAD_LEFT); } else { $hasilkode = "62.10.3213.0001"; } ?&gt; &lt;form class="form-horizontal" action="" method="post" enctype="multipart/form-data"&gt; &lt;div class="form-group"&gt; &lt;label&gt;Nomor Registrasi KTA&lt;/label&gt; &lt;input class="form-control" type="text" name="kode_reg" value="&lt;?=$hasilkode;?&gt;" readonly /&gt; &lt;/div&gt; &lt;div class="form-group"&gt; &lt;label&gt;Nomor KTA&lt;/label&gt; &lt;input class="form-control" type="text" name="no" /&gt; &lt;/div&gt; &lt;div class="form-group"&gt; &lt;label&gt;Nama Perusahaan&lt;/label&gt; &lt;select class="form-control select2" style="width: 100%;" name="nama_perusahaan" id="nama_bu" onchange="changeValue(this.value)"&gt; &lt;option value=""&gt;- Pilih Nama Perusahaan -&lt;/option&gt; &lt;?php $result = mysqli_query($conn, "SELECT * FROM tb_anggota"); $jsArray = "var dtanggta = new Array();\n"; while ($row = mysqli_fetch_array($result)) { echo '&lt;option value="' . $row['nama_bu'] . '"&gt;' . $row['nama_bu'] . '&lt;/option&gt;'; $jsArray .= "dtanggta['" . $row['nama_bu'] . "'] = {nama_pengurus:'" . addslashes($row['nama_pengurus']) . "', alamat:'".addslashes($row['alamat'])."', no_telp:'".addslashes($row['no_telp'])."', npwp_bu:'".addslashes($row['npwp_bu'])."'};\n"; } ?&gt; &lt;/select&gt; &lt;/div&gt; &lt;div class="form-group"&gt; &lt;label&gt;Nama Pimpinan&lt;/label&gt; &lt;input class="form-control" type="text" name="nama_pimpinan" id="nm_peng" readonly /&gt; &lt;/div&gt; &lt;div class="form-group"&gt; &lt;label&gt;Alamat Perusahaan&lt;/label&gt; &lt;textarea class="form-control" type="text" name="alamat_perusahaan" id="almt" readonly&gt;&lt;/textarea&gt; &lt;/div&gt; &lt;div class="form-group"&gt; &lt;label&gt;No. Telepon/HP&lt;/label&gt; &lt;input class="form-control" type="number" name="no_telepon" id="tlp" readonly /&gt; &lt;/div&gt; &lt;div class="form-group"&gt; &lt;label&gt;NPWP Perusahaan&lt;/label&gt; &lt;input class="form-control" type="text" name="npwp_perusahaan" id="npwp" data-inputmask="'mask': ['99.999.999.9-999.999']" data-mask readonly /&gt; &lt;/div&gt; &lt;div class="form-group"&gt; &lt;label&gt;Kualifikasi Perusahaan&lt;/label&gt; &lt;input class="form-control" type="text" name="kualifikasi" /&gt; &lt;/div&gt; &lt;div class="form-group"&gt; &lt;label&gt;Fhoto1&lt;/label&gt; &lt;input class="form-control" type="file" name="fhoto1" /&gt; &lt;/div&gt; &lt;div class="form-group"&gt; &lt;label&gt;Fhoto2&lt;/label&gt; &lt;input class="form-control" type="file" name="fhoto2" /&gt; &lt;/div&gt; &lt;div class="form-group"&gt; &lt;label&gt;Berlaku Sampai&lt;/label&gt; &lt;input class="form-control" type="text" name="berlaku_sampai" id="tgl_berlaku" /&gt; &lt;/div&gt; &lt;div class="form-group"&gt; &lt;button type="submit" name="tambah" class="btn btn-primary"&gt;&lt;i class="fa fa-save"&gt;&lt;/i&gt; Simpan&lt;/button&gt; &lt;button type="reset" class="btn btn-danger"&gt;&lt;i class="fa fa-refresh"&gt;&lt;/i&gt; Reset&lt;/button&gt; &lt;/div&gt; &lt;/form&gt; &lt;?php if(isset($_POST['tambah'])) { $kode_reg = @$_POST['kode_reg']; $no = @$_POST['no']; $nama_perusahaan = @$_POST['nama_perusahaan']; $nama_pimpinan = @$_POST['nama_pimpinan']; $alamat_perusahaan = @$_POST['alamat_perusahaan']; $no_telepon = @$_POST['no_telepon']; $npwp_perusahaan = @$_POST['npwp_perusahaan']; $kualifikasi = @$_POST['kualifikasi'];

			            	$sumber = @$_FILES[&#039;fhoto&#039;][&#039;tmp_name&#039;];
				            $target = &#039;images/upload_anggota/&#039;;
				            $nama_gambar = @$_FILES[&#039;fhoto&#039;][&#039;name&#039;];

			            	$berlaku_sampai = @$_POST[&#039;berlaku_sampai&#039;];
			            	
			            	if($kode_reg == &quot;&quot; || $no == &quot;&quot; || $nama_perusahaan == &quot;&quot; || $nama_pimpinan == &quot;&quot; || $alamat_perusahaan == &quot;&quot; || $no_telepon == &quot;&quot; || $npwp_perusahaan == &quot;&quot; || $kualifikasi == &quot;&quot; || $nama_gambar == &quot;&quot; || $berlaku_sampai == &quot;&quot;) { ?&amp;gt;
			            		&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;
			                        setTimeout(function() {
				                        Swal.fire({
										  	type: &#039;error&#039;,
										  	title: &#039;Oop!&#039;,
										  	text: &#039;Inputan masih belum diisi!&#039;,
										  	showConfirmButton: false,
										  	timer: 3000
										})
			                        	
			                        },20);	
			                  	&amp;lt;/script&amp;gt;
			            		&amp;lt;?php
			            	} else {
			            		$pindah = move_uploaded_file($sumber, $target.$nama_gambar);
			            		if($pindah) { 
			            			mysqli_query($conn, &quot;INSERT INTO tb_kta VALUES (&#039;$kode_reg&#039;, &#039;$no&#039;, &#039;$nama_perusahaan&#039;, &#039;$nama_pimpinan&#039;, &#039;$alamat_perusahaan&#039;, &#039;$no_telepon&#039;, &#039;$npwp_perusahaan&#039;, &#039;$kualifikasi&#039;,  &#039;$nama_gambar&#039;, &#039;$berlaku_sampai&#039;)&quot;) or die (mysqli_error()); ?&amp;gt;
			            			&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;
				                        setTimeout(function() {
					                        Swal.fire({
											  	type: &#039;success&#039;,
											  	title: &#039;Berhasil!&#039;,
											  	text: &#039;Tambah Data KTA telah berhasil...&#039;,
											  	showConfirmButton: false,
											  	timer: 3000
											})
				                        	
				                        },20);
				                        window.setTimeout(function() {
					                        window.location.href=&quot;?page=KTA&quot;;
				                        	
				                        }, 3000);	
				                  	&amp;lt;/script&amp;gt; &amp;lt;?php
			            		} else {
			            			?&amp;gt;
			                        &amp;lt;script type=&quot;text/javascript&quot;&amp;gt;
			                        alert(&quot;Gambar gagal diupload&quot;);
			                        &amp;lt;/script&amp;gt;
			                        &amp;lt;?php
			            		}
			            	}
			            }
						?&amp;gt;
					&amp;lt;/div&amp;gt;
				&amp;lt;/div&amp;gt;
	      	&amp;lt;/div&amp;gt;

	      	&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;   
		    &amp;lt;?php echo $jsArray; ?&amp;gt; 
		    function changeValue(nama_bu){ 
		    document.getElementById(&#039;nm_peng&#039;).value = dtanggta[nama_bu].nama_pengurus; 
		    document.getElementById(&#039;almt&#039;).value = dtanggta[nama_bu].alamat; 
		    document.getElementById(&#039;tlp&#039;).value = dtanggta[nama_bu].no_telp;
		    document.getElementById(&#039;npwp&#039;).value = dtanggta[nama_bu].npwp_bu;
		    }; 
		    &amp;lt;/script&amp;gt;
	    &amp;lt;/div&amp;gt;
	&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;

&lt;/section&gt; <br></pre>

avatar DickyChans58
@DickyChans58

4 Kontribusi 0 Poin

Dipost 3 tahun yang lalu

<div>ini kak yang punya source code saya?</div>

avatar DickyChans58
@DickyChans58

4 Kontribusi 0 Poin

Dipost 3 tahun yang lalu

<div>untuk cara code prosesnya belum bisa, kumohon untuk penjelasannya ?</div>

avatar DickyChans58
@DickyChans58

4 Kontribusi 0 Poin

Dipost 3 tahun yang lalu

Login untuk ikut Jawaban