Update foto php mysqli

Mastah mau nanya, ini ketika update foto file yang di direktori sudah terupdate tapi di webnya tidak berubah gambarnya tetap menampilkan gambar sebelumnya.

Ini potongan code prosesnya

<?php
session_start();

if( !isset($_SESSION['nama_user']) )
{
    header('location:./../'.$_SESSION['akses']);
    exit();
}else{
	include ("config.php");
	$id = $_SESSION['id_user'];
	$sql = "SELECT * FROM user
			WHERE id='$id'";

	# melakukan perintah
	$query = $koneksi->query($sql);

	# check query
	if( !$query )
	{
		die( 'Oops!! Database gagal '. $koneksi->error );
	}

	# check hasil perintah
	if( $query->num_rows > 0)
	{
		# jika data yang dimaksud ada
		# maka ditampilkan
		$row =$query->fetch_assoc();

		# data nama disimpan di session browser
		$nama = $row['Nama'];
		# $_SESSION['akses']	   = $row['hak_akses'];
	}
    $akses = $_SESSION['akses'];
    $uname = $_SESSION['u_name'];
    $sqli = mysqli_query($koneksi, 'Select * from artikel');
    $queri = "SELECT * FROM user WHERE id='$id'";
	$lakukan = mysqli_query($koneksi, $queri);
    $tampilkan = mysqli_fetch_array($lakukan);

    $nim = $_GET['nim'];
			$mysql = mysqli_query($koneksi, "SELECT * FROM logo WHERE id='$nim'");
			if(mysqli_num_rows($mysql) == 0){
				echo '<div class="alert alert-danger">Tidak ada data</div>';
			}else{
				$baris = mysqli_fetch_assoc($mysql);
			}
			if(isset($_FILES['fileToUpload'])){
				$target_dir = "avatar/";
				$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
				$uploadOk = 1;
				$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);

				if(isset($_POST["upload"])) {
					$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
					if($check !== false) {
						$uploadOk = 1;
					}
				}

				if ($_FILES["fileToUpload"]["size"] > 500000) {
					echo '<div class="alert alert-danger">File size terlalu besar.</div>';
					$uploadOk = 0;
				}

				if($imageFileType != "png" ) {
					echo '<div class="alert alert-danger">Hanya PNG yang di izinkan.</div>';
					$uploadOk = 0;
				}

				if ($uploadOk == 0) {
					echo '<div class="alert alert-danger">File gagal di upload.</div>';
				} else {
					$file = $target_dir.''.$nim.'.'.$imageFileType;
					$new_nim = $nim.'.'.$imageFileType;
					if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $file)) {
						$up = mysqli_query($koneksi, "UPDATE logo SET logo='$new_nim' WHERE id='$nim'");
						if($up){
							header('Location: '.$url.'/'.$_SESSION['akses'].'/logoWeb.php?nim='.$nim.'&sukses=ya');
							exit();
						}
					} else {
						echo '<div class="alert alert-danger">File gagal di upload.</div>';
					}
				}
			}

			if(isset($_GET['sukses']) == 'ya'){
				echo '<div class="alert alert-success">File berhasil di upload.</div>';
			}
}

require("config.php")
?>

ini potongan kode formnya

<div class="row">
			<div class="col-lg-12">
				<center><h2>Logo Web</h2></center>
			</div>
		</div><!--/.row-->
		<div style="background-color: #ffffff;
         	border-radius: 5px;
         	box-shadow: 5px 5px 0 rgba(0 , 0 , 0 , 0.16) , 0 2px 5px 0 rgba(0 , 0 , 0 , 0.12);
         	color: black;
         	font-size: 18px;
         	font-weight: bold;
         	margin: 0.5rem 0 1rem;
         	overflow: hidden;
         	padding: 20px;
         	position: relative;
         	transition: 0.25s;">
			<center>
			<div class="col-md-6 col-md-offset-3 text-center">
				<img class="rounded" src="avatar/<?php echo $baris['logo']; ?>" width="150"><br /> <br/>
				<form class="form-inline" method="post" enctype="multipart/form-data">
					<div class="form-group">
						<div class="col-sm-10">
							<div class="input-group">
								<span class="input-group-btn">
									<span class="btn btn-primary btn-file">
										Browse… <input type="file" name="fileToUpload">
									</span>
								</span>
								<input type="text" class="form-control" readonly>
							</div>
						</div>
						<div class="col-sm-2">
							<input type="submit" name="upload" class="btn btn-primary" value="Upload">
						</div>
					</div>
				</form>
		</div></center>
		</div>
	</div>
</div>

	<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
	<script src="js/bootstrap.min.js"></script>
	<script>
	$(document).on('change', '.btn-file :file', function() {
		var input = $(this),
		numFiles = input.get(0).files ? input.get(0).files.length : 1,
		label = input.val().replace(/\\/g, '/').replace(/.*\//, '');
		input.trigger('fileselect', [numFiles, label]);
	});

	$(document).ready( function() {
		$('.btn-file :file').on('fileselect', function(event, numFiles, label) {
			var input = $(this).parents('.input-group').find(':text'),
				log = numFiles > 1 ? numFiles + ' files selected' : label;
			if( input.length ) {
				input.val(log);
			} else {
				if( log ) alert(log);
			}
		});
	});
	</script>
	</body>

Tolong bantuannya suhu suhu.... :))

avatar desinourma
@desinourma

4 Kontribusi 0 Poin

Dipost 5 tahun yang lalu

Tanggapan

Pastiin dulu masuk gk gambarnya ke database

sudah masuk bos. cuma pas berhasil gambarnya tetep yang lama bukan yang baru. di folder gambarnya udah ganti yang baru.

udah clear cache?

Thankyou bang, ternyata permasalahannya dari sana. Dapet ilmu baru nih, ternyata pengaruh.

1 Jawaban:

Jawaban Terpilih

Clear Cache

avatar desinourma
@desinourma

4 Kontribusi 0 Poin

Dipost 5 tahun yang lalu

Login untuk ikut Jawaban