Postingan lainnya
update banyak gambar php mysqli
halo, saya lagi ngerjain projek untuk tugas akhir soal sistem informasi geografis pemetaan perumahan, saya ada bermasalah di update banyak gambar, yang saya pengen adalah : kalau saya pilih gambar baru, gambarnya terupdate di database, kalau tidak, datanya tidak terupdate.
ini function ubahgambar nya :
function ubahgambarperum($data){
global $conn;
$gambarLama = htmlspecialchars ($data["gambarLama"]);
$gambar = upload_perum();
//cek apakah user pilih gambar baru atau tidak
if( $_FILES['gambar']['error'] == 4){
$gambar = $gambarLama;
} else {
$gambar;
}
return mysqli_affected_rows($conn);}
dan ini function upload gambarnya :
function upload_perum() {
global $conn;
$sizeGambar = 10 * 1024 * 1024;
$idPerum = $_POST["id"];
foreach($_FILES["gambar_perum"]["tmp_name"] as $x=>$tmp_name){
$namaFile = $_FILES['gambar_perum']['name'][$x];
$ukuranFile = $_FILES['gambar_perum']['size'][$x];
$tmpName = $_FILES['gambar_perum']['tmp_name'][$x];
$tipe_file = pathinfo($namaFile, PATHINFO_EXTENSION);
$error = $_FILES['gambar_perum']['error'];
// cek apakah gambar sudah di upload
if ($error == 4){
echo "
<script>
alert('Gambar belum dimasukkan!')
</script>
";
return false;
}
$ekstensiGambarValid = array('jpg', 'jpeg', 'png');
$ekstensiGambar = explode('.', $namaFile);
$ekstensiGambar = strtolower(end($ekstensiGambar));
if(!in_array($ekstensiGambar, $ekstensiGambarValid)){
echo "
<script>
alert('Format gambar tidak didukung!')
</script>";
return false;
}
if($ukuranFile > $sizeGambar){
echo "
<script>
alert('Ukuran gambar terlalu besar!')
</script>";
return false;
}
//ambil nama perumahan untuk dimasukkan sebagai nama gambar dari table tiperumah
$namaPerum = $_POST["nama_perum"];
$selectPerum = query("SELECT * FROM perumahan_master WHERE id_perum = '$idPerum'")[0];
$idPerum = $selectPerum["id_perum"];
$namaPerum = $selectPerum["nama_perum"];
// jika lolos pengecekan, gambar siap di upload
// generate nama baru
$namaFileBaru = 'Perum'.'-'. $namaPerum . '-'. $x;
$namaFileBaru .= '.';
$namaFileBaru .= $tipe_file;
move_uploaded_file($tmpName, '../img-perum/' . $namaFileBaru);
$queryupdateGambar = " UPDATE perum_gambar
SET
gambar_perum = '$namaFileBaru'
WHERE id_perum = $idPerum";
mysqli_query($conn, $queryupdateGambar);
}
return $namaFileBaru;
}
1 Jawaban:
<div><a href="https://www.thehotarticle.com/seo">what is search engine optimization</a><br>he then shot a very last-spherical 76 on the carmel, ind., path on wednesday to finish in a tie for 2nd with a 4-over 220, 4returned of winner john marshall butler.i played super,” daly ii advised the indianapolis megastar. “it'd had been cool to win, however i still have time. just a couple horrific 3-putts each days, however apart from that i played incredible.</div>