themetman's picture

I am busy creating my 4th Custom Module for my own use. I use PhpStorm for the php dev on Gentoo Linux

I have done this before on my other modules, but images not showing on this one!! I have some text and display two CSV files in tables which all shows fine on the page. Looking at the page source, the <img src="...> element is there

here is some of the code for the markup

$basefolder = BACKDROP_ROOT . '/files/met/seaiceArchiveSummary/';
$uri_nhmin = $basefolder . 'NH_Min2019_small.png';
$build[] = array(
  '#theme' => 'image',
  '#uri' => $uri_nhmin,
);

When I look at the variable $uri_nhchart I know it is correct because I can copy it and do this in a terminal

ls /PATH/TO/FILE/NH_Min2019_small.png

and the file is there.

Also no errors in the site logs. as per the access log gives an http 200 code:

"GET /home/francis/FG-Docs/public_html/moduledev.bd/web/files/met/seaiceArchiveSummary/NH_Min2019_small.png HTTP/1.1" 200 

Accepted answer

For anyone also having a problem.......

I think I have worked out the answer after a lot of looking in the logs and stepping through the module. It is all to do with mixing System Paths and Website Paths

My BACKDROP_ROOT is in the 'web' folder of the Site.

To display an image you have to use the $basefolder as below with the following

$root = BACKDROP_ROOT;
$basefolder = '/web/files/met/seaiceArchiveSummary/';
$uri_nhmin = $basefolder . 'NH_2019Min_small.png';

NOT with this:

$root .  /files/met/seaiceArchiveSummary/ . $uir_nhmin

So when you try to create the image using this:


$build[] = array(
  '#theme' => 'image',
  '#uri' => $uri_nhmin,
);

Your path would look like this in $uri_nhmin

/web/files/met/seaiceArchiveSummary/NH_2019Min_small.png

Now if you then try and use glob to get a list of files, you have to use a System Path, not a Website Path, then use the basename() to get the filename and then append it to the $basefolder so the #uri is a Web Path, not a System Path..

I should have known this, but it had escaped me today for some reason.

Comments

HAving difficulty understanding what you mean to be honest.

themetman's picture

I have created a module to display some csv files and images on a page.

The CSV files display as a table, but the images do not.

I have moved the module to my laptop, and on there Apache is reporting that the images cannot be found (404 code), but they are there when I check in the terminal.

Here are a couple of lines from the Apache access log

/FG_Modules/seaice_archive HTTP/1.1" 404
/var/www/html/tbd.local/web/files/met/seaiceArchiveSummary/NH_2018Min_small.png

When I go into a terminal and check for the file with an ls -l <FILENAME> the file is found

-rw-rw-r-- 1 francis apache 31142 Apr 25 09:08 /var/www/html/tbd.local/web/files/met/seaiceArchiveSummary/NH_2018Max_small.png

As you can see the permissions are OK.

Here is the source of the page for that image which looks OK to me.

<img src="/var/www/html/tbd.local/web/files/met/seaiceArchiveSummary/NH_2018Min_small.png" alt="" />

so why is the image not displayed?

themetman's picture

For anyone also having a problem.......

I think I have worked out the answer after a lot of looking in the logs and stepping through the module. It is all to do with mixing System Paths and Website Paths

My BACKDROP_ROOT is in the 'web' folder of the Site.

To display an image you have to use the $basefolder as below with the following

$root = BACKDROP_ROOT;
$basefolder = '/web/files/met/seaiceArchiveSummary/';
$uri_nhmin = $basefolder . 'NH_2019Min_small.png';

NOT with this:

$root .  /files/met/seaiceArchiveSummary/ . $uir_nhmin

So when you try to create the image using this:


$build[] = array(
  '#theme' => 'image',
  '#uri' => $uri_nhmin,
);

Your path would look like this in $uri_nhmin

/web/files/met/seaiceArchiveSummary/NH_2019Min_small.png

Now if you then try and use glob to get a list of files, you have to use a System Path, not a Website Path, then use the basename() to get the filename and then append it to the $basefolder so the #uri is a Web Path, not a System Path..

I should have known this, but it had escaped me today for some reason.