简体   繁体   中英

images will not upload properly from images folder with php

I wrote a function to upload image files from a folder to a web page with PHP. The HTML outputs correctly, but the images do not display. When I check the web console I see an "i" in place of the source for my image. I'm sure what's going on here because I do see the correct amount of broken links just not the image

    <?php
    // grabs work.php imgs from imgs folder

    $files = GLOB('imgs/*.*');

    //PRINT_R($files);

    function generateImgs($items) {
    $html = "<div class=\"container\">
                <ul class=\"row\">\n";
    foreach ($items as $item){
        $html .= "<li class=\"col-lg-2 col-md-2 col-sm-3 col-xs-4\"><img src=\"imgs/$item[0]\"/></li>\n";
    }
    $html .= "</ul> </div>\n";
    return $html;
    }

    echo generateImgs($files);

    ?>

After messing around a little and changing

     <img src=\"imgs/$item[0]\"/>

to

     <img src=\"./$item'[0]'\"/>

I'm now seeing the whole path to displayed to the img in the web console but there is a trail of characters after the file name which are %27%5B0%5D%27 . This string is at the end of every GET request for the image files.

Use this code instead:

foreach ($items as $item){
    $html .= "<li class=\"col-lg-2 col-md-2 col-sm-3 col-xs-4\"><img src=\"imgs/$item\"/></li>\n";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM