$filename = ' '; //ที่อยู่ภาพ if (file_exists($filename)) { //โค้ดเมื่อเจอไฟล์ }
<?php $objConnect = mysql_connect("localhost","root","12345678") or die("Error Connect to Database"); $objDB = mysql_select_db("project"); $strSQL = "SELECT * FROM tb_image where id_room ='4705' order by id_room asc "; $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]"); ?> <table width="340" border="1"> <tr> <th><div align="center">แถว</div></th> <th><div align="center">c1</div></th> <th><div align="center">c2</div></th> <th><div align="center">c3</div></th> <th><div align="center">c4</div></th> <th><div align="center">c5</div></th> <th><div align="center">c6</div></th> <th><div align="center">c7</div></th> <th><div align="center">c8</div></th> <th><div align="center">c9</div></th> <th><div align="center">c10</div></th> <th><div align="center">c11</div></th> <th><div align="center">c12</div></th> <th><div align="center">c13</div></th> </tr> <?php while($objResult = mysql_fetch_array($objQuery)) { ?> <tr> <td><center><?=$objResult["id_image"];?></center></td> <td><center><img src="myimage/<?=$objResult["c1"];?>"></center></td> <td><center><img src="myimage/<?=$objResult["c2"];?>"></center></td> <td><center><img src="myimage/<?=$objResult["c3"];?>"></center></td> <td><center><img src="myimage/<?=$objResult["c4"];?>"></center></td> <td><center><img src="myimage/<?=$objResult["c5"];?>"></center></td> <td><center><img src="myimage/<?=$objResult["c6"];?>"></center></td> <td><center><img src="myimage/<?=$objResult["c7"];?>"></center></td> <td><center><img src="myimage/<?=$objResult["c8"];?>"></center></td> <td><center><img src="myimage/<?=$objResult["c9"];?>"></center></td> <td><center><img src="myimage/<?=$objResult["c10"];?>"></center></td> <td><center><img src="myimage/<?=$objResult["c11"];?>"></center></td> <td><center><img src="myimage/<?=$objResult["c12"];?>"></center></td> <td><center><img src="myimage/<?=$objResult["c13"];?>"></center></td> </tr> <?php } ?>
. . . function filechk($filepart) { //สร้าง function เช็คไฟล์ $filename = "myimgage/".$filepart; //กำหนดที่อยู่ไฟล์ if (file_exists($filename)) { //เช็คว่ามีไฟล์อยู่หรือไม่ echo $filename; //แสดงผล } } . . . <td><center><img src="<? filechk($objResult["c1"]); ?>"></center></td> //เอาผลจากการ query เข้า function . . .
function displayImage($cellPart) { $fullUrl = 'http://mydomain.tld/myimage/' . $cellPart; $file_headers = @get_headers($fullUrl); if ( !is_array($file_headers) || ( isset($file_headers[0]) && ( strpos($file_headers[0], '404') !== false || strpos($file_headers[0], '301') !== false || strpos($file_headers[0], '302') !== false ) ) ) { // ไม่มีภาพ, แสดงภาพขาว return 'white-image-url.jpg'; } else { // มีภาพ return $fullUrl; } }
<img src="<?php echo displayImage($objResult["c13"]); ?>">
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง