Reputation: 21
For some reason exif_read_data() returns false on every image in the directory even though I know that all my jpeg images have metadata properties.
I am by no means a PHP wizard yet so perhaps I have a syntax error or I'm just missing something fairly obvious to those of you who are PHP wizards.
galleryData.metadata = <?php
$dir_path = "Assets/Images/portfolio/";
if (is_dir($dir_path)) {
$files = scandir($dir_path);
for ($i = 0; $i < count($files); $i++) {
$tempPath = $dir_path + $files[$i];
$metadata[$i] = exif_read_data($tempPath);
}
echo json_encode($metadata);
}
?>;
Upvotes: 1
Views: 1311
Reputation: 91
might be a solution, but need to have more info real error (error message ?)
exif_read_data() can be buggy prom php version to version: Bug #75785 Many errors from exif_read_data
The solution might be to use
$img = new \Imagick(DSC01386.jpg);
$allProp = $img->getImageProperties();
$exifProp = $img->getImageProperties("exif:*");
The Imagick class, is quite powerful class (rotations etc).
The full story for that solution here
Upvotes: 1
Reputation: 21
Thankfully figured it out I wasn't combining my strings properly. Below is my fixed and working code.
galleryData.metadata = <?php
$metadata = array();
if (is_dir($dir_path)) {
for ($i = 0; $i < count($files); $i++) {
$metadata[$i] = exif_read_data("{$dir_path}{$files[$i]}", null, true);
}
echo json_encode($metadata);
}
?>;
Upvotes: 1