Quote:จะ echo รูปภาพของ Users ทีมีใน database เมื่อมีการ login เข้ามา จะ echo รูปภาพของ Users คนนั้นๆ อย่างไรครับ 1.register เก็บรูปไว้ที่ folder images 2.login users ตอนนี้ที่รูปแสดงโดยใช้ src อยู่ 3.อยากทราบ เมื่อมีการ login เข้ามา จะ echo รูปภาพของ Users คนนั้นๆ อย่างไรครับ ที่ให้ไปแทน src ข้อ2
<?php define( 'web_path', '/image/'); define( 'srv_path', 'c:\hostpath\image\'); $fn = 'avatar_'.$user_id.'.png'; ?> <img src="<?=web_path . (file_exits(srv_path . $fn)? $fn : 'temp.png')?>" >
<?php require_once('database/connection.php'); / if (isset($_POST['submit'])) { $username = $conn->real_escape_string($_POST['username']); $password = $conn->real_escape_string($_POST['password']); date_default_timezone_set('Asia/Bangkok'); $Newtime = date('Y-m-d H:i:s'); $Newtime1 = date('Y-m-d H:i:s'); $sql = "SELECT * FROM `user` WHERE `username` = '".$username."'"; $result = $conn->query($sql); $row = $result->fetch_assoc(); if(!empty($row)){ if(password_verify($password, $row['password'])){ $update = "UPDATE `user` SET updated_at = '$Newtime', updated_dt = '$Newtime1' WHERE `username` = '$username'"; $runupdate = $conn->query($update); $_SESSION['id'] = $row['id']; $_SESSION['firstname'] = $row['firstname']; $_SESSION['lastname'] = $row['lastname']; $_SESSION['username'] = $row['username']; $_SESSION['password'] = $row['password']; $_SESSION['created_at'] = $row['created_at']; $_SESSION['updated_at'] = $Newtime; $_SESSION['updated_dt'] = $Newtime1; $_SESSION['userlevel'] = $row['userlevel']; if ($_SESSION['userlevel'] == 'admin') { echo "<script>alert('เข้าสู่ระบบสำเร็จ...'); window.location ='../cmssystem/pages/admin/dashboard/';</script>"; } if ($_SESSION['userlevel'] == 'member') { echo "<script>alert('เข้าสู่ระบบสำเร็จ...'); window.location ='../cmssystem/pages/users/dashboard/';</script>"; } } else { echo '<script> alert("username หรือ password ไม่ถูกต้อง") </script>'; header('Refresh:0; url=index.php'); } }else{ echo '<script> alert("ไม่สามารถเข้าสู่ระบบได้โปรดกรอกข้อมูลใหม่อีกครั้ง")</script>'; header("Refresh:0"); } } ?>
//1636133254.png ไฟล์รูปจะตรงกับ รูปที่1 ด้านบนครับ <div class="image"> <img src="../../../pages/images/1636133254.png" class="img-circle elevation-2" alt="User Image"> </div> <div class="info"> <a href="../manager/" class="d-block">ยินดีต้อนรับคุณ: <?php echo $_SESSION['username'];?> </a> </div>
//$user_image = รูปที่ได้จากฐานข้อมูล <img src="../../../pages/images/<?php echo $user_image;?>" class="img-circle elevation-2" alt="User Image">
<img src="../../../pages/images/<?php echo $_SESSION['image'];?>" class="img-circle elevation-2" alt="User Image">
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง