簡體   English   中英

如果使用 PHP 的數據表中沒有圖像,如何隱藏字段?

[英]how to hide field If image is not available in Datatables using PHP?

在此處輸入圖像描述

當用戶不上傳圖像時,我想隱藏圖像字段。

<tr align="center">
    <td><?php echo $result['id'] ?></td>
    <td><?php echo $result['user_id']?></td>
    <td><?php echo $result['username']?></td>
    <td><?php echo $result['subject']?></td>
    <td>
    <?
        
    if (file_exists(public_path("images/".$result['image'].""))){
        unlink(public_path("images/".$result['image']."")); {?>
        <a target="_blank" href="<?php echo "images/".$result['image']."" ?>">
        <img src=<?php echo "images/".$result['image'].""?>
        style="height: 150px; width: 150px" /></a>
    <? } }  else {
            echo "Image not available";
    } 
    ?>
    </td>
    <td><?php echo $result['question']?></td>
    <td><a href="#?id=<?=$result['id']?>">
    <input type="Button" name="reply" value=Reply id="reply" onclick="togglePopup()" /></a></td>
</tr>

當我單擊圖像時,它會將我重定向到我的圖像目錄。 當我單擊圖像時,它會在新選項卡中打開(如果圖像可用),如果圖像不可用,它不會打開。? 請任何人幫助我。

使用此代碼:

<?php if(file_exists("images/".$result['image'])){ ?>
    <a target="_blank" href="<?php echo "images/".$result['image']."" ?>">
        <img src=<?php echo "images/".$result['image']."" ?> style="height: 150px; width: 150px" />. 
  </a>
<?php } else {
    //
} ?>

此代碼檢查圖像是否可用

首先,您必須檢查$result['image']中有一個值,然后檢查服務器中是否存在圖像file_exists("images/".$result['image'])

<?php if(isset($result['image']) && file_exists("images/".$result['image'])){ ?>
    <a target="_blank" href="<?php echo "images/".$result['image']."" ?>">
        <img src=<?php echo "images/".$result['image']."" ?> style="height: 150px; width: 150px" />. 
  </a>
<?php } else {
    //
} ?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM