ตรวจสอบรูปแล้วแสดงรูปภาพ
เป็นการตรวจสอบรูป ว่ามีรูปไหม ถ้ามีให้แสดงรูป ออกมา ถ้าไม่มีให้แสดงรูป No photo มา
เอาแบบ ง่ายๆ ก็
<img src="../images <? if($str_filepicname!="")echo $str_filepicname; else echo '$str_defaultfilepicname' ?>">
//////////////////////////////////////////////
เอาแบบ ยาวๆก็
$str_defaultfilepicname = "00.png"; // ให้ไฟล์รูปชื่อ 00.png เป็นรูป Default
$str_filepicname = "01.png"; // ให้ไฟล์รูปชื่อ 01.png เป็นรูปที่ต้องการตรวจสอบ
$str_imgpath = "../images/"; // Path รูป
$str_imgfullpath = $str_imgpath . $str_filepicname; // นำ Path รูป มาเชื่อมกับ ชื่อรูป
if (file_exists($str_imgfullpath)) // ตรวจสอบว่ามีไฟล์รูปตาม Path ในตัวแปร $str_imgfullpath หรือไม่
{
$str_imgfullpath = $str_imgpath . $str_filepicname; // ถ้ามีไฟล์รูปให้ Path ชี้ที่ไฟล์รูปที่ต้องการ
}
else
{
$str_imgfullpath = $str_imgpath . $str_defaultfilepicname; // ถ้าไม่มีไฟล์รุปให้ Path ชี้ไปที่ไฟล์รูป Default
}
?>
{
$str_imgfullpath = $str_imgpath . $str_defaultfilepicname; // ถ้าไม่มีไฟล์รุปให้ Path ชี้ไปที่ไฟล์รูป Default
}
?>
<img src='<?php echo $str_imgfullpath; // นำ Path ที่ได้มาใส่ใน Attribute src เพื่อทำการแสดงรูป ?>'/>
ไปเจอมาจาก AMI KNOWLEDGE
ไปเจอมาจาก AMI KNOWLEDGE
/////////////////////////////
file_exists คือ ฟังชั่นของ PHP ไว้ตรวจเช็คว่ามีชื่อไฟล์นั้นอยู่หรือเปล่า