0

In the following code I'm setting some variables with info about the image (like the title, URL, etc.)

location /photo {
    ssi on;
    ssi_last_modified on;
    set $photosrc /photos/$request_basename;
    set $phototitle $request_basename;
    ...
}

I would like to show the photo's creation date on the page. Ideally it should be in another variable…:

   ...
   set $photodate $???;
   ...

but AFAICT there is no variable in NGINX that contains the last modified date. I've looked through the variable index but I couldn't find anything. Nginx automatically adds the modified date to the Last-Modified header, so it should be capable of this. I've also tried using ssi_last_modified but according to some answers it won't work because NGINX never implemented full SSI.

1 Answers1

0

File modification time is NOT the same as the photo creation date.

While it would be simple to force the mtime to match the EXIF data and use that as a proxy for the data you actually want to report, there's potentially other data which can be embedded in the file which might be useful. This sounds like the XY problem.

Assuming that you don't already have any application server capability on the host, then adding it just to solve this problem seems like overkill (and opens the door to a lot of hardening complications). So if it were me, I'd just write a crawler to dump the data into a machine readable format inside the document root, e.g.

#!/bin/bash

if [ ! -f /var/run/lastexif ] ; then touch -t 198012250200 /var/run/lastexif fi mv -f /var/run/lastexif /var/run/lastexif.old touch /var/run/lastexif find /var/www/html/photo -type f -newer /var/run/lastexif.old | dump_exif_data

Where dump_exif_data is something like....

#!/bin/bash

while read fname do if [ -n "$fname" -a -f "$fname" ] ; then exiftool "$fname" | tr -s ' ' > "${fname}.exif" fi done

Sprinkle some ajax magic on your pages, add a cron job (or incron job) to run the script and job done.

symcbean
  • 23,767
  • 2
  • 38
  • 58