简体   繁体   English

图像将无法使用PHP从图像文件夹正确上传

[英]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. 我编写了一个函数,可以使用PHP将图像文件从文件夹上传到网页。 The HTML outputs correctly, but the images do not display. HTML正确输出,但是图像不显示。 When I check the web console I see an "i" in place of the source for my image. 当我检查Web控制台时,我看到“ i”代替图像源。 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 . 现在,我在Web控制台中看到要显示到img的整个路径,但是在文件名之后有%27%5B0%5D%27字符是%27%5B0%5D%27 This string is at the end of every GET request for the image files. 该字符串位于图像文件的每个GET请求的末尾。

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";
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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