OK, that actually means EXIF is working, I checked another way:
PHP Code:
<!DOCTYPE html>
<html>
<head>
<title>EXIF Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<?php
$exif = exif_read_data('http://www.claragraceroman.com/images/album0206/017.jpg');
echo $exif['FileDateTime'];
?>
</body>
</html>
I got:
0
Which (in PHP and in javascript) is that EST date. That means the EXIF FileDateTime for that file is 0. I checked the full EXIF and it is. It reports the camera as iPhone. So I guess it doesn't save that. I have a Konica Minolta that does, so I was going on that. The EXIF from that image does have an accurate value for DateTimeOriginal, but it's in a different format.
So we can do:
PHP Code:
<!DOCTYPE html>
<html>
<head>
<title>EXIF Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<script type="text/javascript">
var d0 = '<?php
$exif = exif_read_data('http://www.claragraceroman.com/images/album0206/017.jpg');
echo $exif['DateTimeOriginal'];
?>'.split(/[ :]/g);
document.write(new Date(d0[0], --d0[1], d0[2], d0[3], d0[4], d0[5]));
</script>
</body>
</html>
and get:
Tue Aug 06 2013 06:47:29 GMT-0400 (Eastern Daylight Time)
Which I think is what we are after. If so this should work as the getalbumpics.php file:
PHP Code:
<?php
Header("content-type: application/x-javascript");
function returnimages(){
$photovar = isset($_GET['id'])? $_GET['id'] : 'galleryarray';
if (!preg_match('#^[a-z_][a-z0-9_]+$#i', $photovar)){
echo 'alert("id/array name must be at least two characters and contain only letters, numbers, or underscore, and cannot start with a number")';
die();
}
$path = str_replace(' ', '%20', str_replace($_SERVER['DOCUMENT_ROOT'], '', str_replace('\\', '/', getcwd())));
$base = '//' . preg_replace('#/{2,}#', '/', "{$_SERVER["SERVER_NAME"]}/$path/");
$dirname = '.';
$pattern = '#\.(jpg|jpeg|png|gif|bmp)$#i';
if($handle = opendir($dirname)){
clearstatcache();
while(false !== ($file = readdir($handle))){
if(preg_match($pattern, $file)){
@$filedate = exif_read_data($file);
if($filedate && isset($filedate['DateTimeOriginal'])){
$filedate = strtotime($filedate['DateTimeOriginal']);
} else { $filedate = filemtime($file); }
$files[$file] = $filedate;
}
}
closedir($handle);
}
arsort($files, SORT_NUMERIC);
$count = -1;
foreach ($files as $file => $time){
$jsarray[] = "[" . ++$count . ", '$file', '" . date("M d, Y", $time) . "']";
}
return "var $photovar = {\n\tbaseurl: '$base',\n\timages: [\n\t\t" . implode(",\n\t\t", $jsarray) . ",\n\t\t['placeholder']\n\t],\t\n\tdesc: []\n};";
}
echo returnimages();
die();
?>
BTW, as long as all of the images have this data, it already sorts the files in order from newest to oldest, so you don't have to sort them in the javascript part. But you can, it shouldn't hurt anything. But if not all of the images have that data, then those that don't will use the filetime timestamp, so will appear more recent (time of upload) in either a javascript or PHP sort.
If you don't have javascript sort the dates, you can get a little more creative in formatting them in PHP, like - "M jS, Y", which would give you dates like - Aug 6th, 2013.
The browser cache may need to be cleared and/or the page refreshed to see changes.
Note: The line:
Code:
$filedate = strtotime($filedate['DateTimeOriginal']);
or other minor parts of the PHP code might have to be expanded upon, changed or even replaced by a few lines of code for your version of PHP.
Bookmarks