简体   繁体   English

获取存储图像时,来自Raspberry Pi服务器的响应中断

[英]Broken response from Raspberry Pi server when GETting stored images

I have a Raspberry Pi server which has PNG images saved on it. 我有一台Raspberry Pi服务器,上面已保存了PNG图像。 I am trying to GET the images from the server and append them all to an HTML element. 我正在尝试从服务器获取图像并将它们全部附加到HTML元素。 All of the relevant files (the images, HTML, JavaScript, and PHP) are all stored in /var/www/html . 所有相关文件(图像,HTML,JavaScript和PHP)都存储在/var/www/html

File load.php : 文件load.php

<?php
$dirname = "/var/www/html/";
$images = glob($dirname."*.png");
$data = '<ul>';
foreach($images as $image) {
  $data .= '<li><img src="'.$image.'" /></li>'; // append all images
}
$data .= '</ul>';
echo $data;
?>

JavaScript function: JavaScript函数:

function loadImg(){
    $.ajax({
        type: "GET",
        url: "load.php",
        success: function(data){
            console.log(data); // To check something there
            $("#imgsDiv").html(data);
        }
    });
}

However, this functionality does not work and only displays the traditional broken image icon onto the 'imgsDiv'. 但是,此功能不起作用,只能在“ imgsDiv”上显示传统的破碎图像图标。

I really have no idea why it can't display the images from the server. 我真的不知道为什么它不能显示来自服务器的图像。 It is not an issue with folder permissions as I am able to load single named images into img srcs. 文件夹权限不是问题,因为我能够将单个命名的图像加载到img srcs中。

This is the HTML when I inspect the page: 当我检查页面时,这是HTML:

在此处输入图片说明

I also get a 404 error saying that the page can't find the resource: http://192.168.1.201/var/www/html/image.png , etc. for all of the listed images. 我还收到一个404错误,指出该页面找不到资源: http : //192.168.1.201/var/www/html/image.png等,用于所有列出的图像。

It Seems the PHP code was bugging out with me having declared the directory: 似乎PHP代码在声明目录的过程中困扰着我:

$dirname = "/var/www/html/";
$images = glob($dirname."*.png");

It should just be: 应该只是:

$images = glob("*.png");

And the PHP code looks in the correct directory for the images ans successfully displays them. PHP代码会在正确的目录中查找图像并成功显示它们。

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

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