jeudi 8 août 2019

Last elseif statement does not work in PHP

On the homepage of the website, I do a check query when I get pictures of post cards from the database. I don't have very deep algorithms and knowledge of PHP, but for now it seemed to handle.

There are two options when uploading images to post either image url or upload file. When I get the data from the data file with the variable before the end of the path is set into the SRC, so the picture is on the server if there is a check on the server if the second stage of the URL is passed to another site where the image is taken. If I don't have data in mysql, I want the img tag to show a fixed image but I couldn't do it somehow. It doesn't happen when you do "Elseif () {}" or "else". If you pass the code to the end of the code and add only a fixed picture is taken. but it naturally takes the picture below. Outside the Elseif structure. Now how do I apply a fixed image if the image url doesn't exist? Thank you in advance for your help.

I work Apache and PHP7.x by xampp. first two if statement has worked. but third does not work. I have tried just else and else if and elseif but none of them has not run.


foreach ($homepage_contents as $key => $value) {
    ?>
        <div class="kutu shadow z-depth-1 rounded">


        <div style="position: relative;">
        <a id="content_title_link" href="index.php?url=icerik&id=<?=$value->icerik_id; ?>"> 

        <?php


    $fixed_img = '<img src="public/img/turkbayrak.JPG" alt="">';
    $dosya = "public/upload/$value->icerik_foto"; // ../upload/picture.jpg

    $img_url = "$value->icerik_foto"; //src="example.com/picture.jpg
    $img_url_length = var_export(mb_strlen($img_url,'utf8'));
    print_r($resim_url_length);                                 

    if (file_exists($dosya)) {
        echo '<img src="'.$dosya.'">';
    }elseif (strlen($img_url)>=2) {
        echo '<img src="'.$img_url.'">';
    }elseif(empty($img_url)||strlen($img_url)<2){

        echo 'Hello World';
        echo $fixed_img;

    }                                         

    if(strlen($img_url)<2){

        echo $fixed_img;
    }                                 

    ?>

I am expecting that the 3rd. elseif command will work. And if there is no url or image file it will use fixed-image that is descripted before.

!first card has no img from database in picture below link. so I set an fixed img but it does not work in elseif Image of Website's Last condition

Aucun commentaire:

Enregistrer un commentaire