0

I am trying to get the created date and time of an image using php.I am using php 7.1. After lots of searching and RND I got one php function named exif_read_data to get the details of an image. But using this library I am not getting any desired output. First thing is, it is only supporting JPG file. While I need to get any type of image data. At least JPG and PNG. Second things is it is giving me current time always.

Here is my code that I had tried so far.

$randomNumber = rand();
$extention = pathinfo($this->request->data['patient_image']['name'], PATHINFO_EXTENSION);
$imageName= 'image'.$randomNumber.'.'.$extention ;
$uploadPath = WWW_ROOT.'img/patient-images/';
$uploadFile = $uploadPath.$imageName; 
move_uploaded_file($this->request->data['patient_image']['tmp_name'], $uploadFile);
$content = 'img/patient-images/'.$imageName;
$filedata = exif_read_data($content);

The output I am getting after doing var_dump($filedata) is -

array:7 [▼
 "FileName" => "image300414002.jpg"
 "FileDateTime" => 1601989985
 "FileSize" => 67396
 "FileType" => 2
 "MimeType" => "image/jpeg"
 "SectionsFound" => ""
 "COMPUTED" => array:4 [▼
   "html" => "width="512" height="512""
   "Height" => 512
   "Width" => 512
   "IsColor" => 1
 ]
]

Now if I convert FileDateTime then it is returning me current date and time.

Fokrule
  • 844
  • 2
  • 11
  • 30
  • Does this answer your question? [Getting "Taken Date" of a photo instead of "Modified Date" with PHP exif\_read\_data](https://stackoverflow.com/questions/13674296/getting-taken-date-of-a-photo-instead-of-modified-date-with-php-exif-read-da) – francisco neto Oct 06 '20 at 14:19
  • No. As I already mentioned that I am using this php function but still I am not getting the data whatever is needed. And in this answer it is showing about uses of that library. – Fokrule Oct 06 '20 at 14:50
  • you have to extract the `DateTimeOriginal`property of the array returned by `exif_read_data`. And it seems that the image you are testing doesn't have this information (it may have been stripped in the saving process etc). To find out if the problem is with your image, you may try with a picture that actual has exif complete information, for example that picture here: https://github.com/ianare/exif-samples/blob/master/jpg/Canon_40D.jpg – francisco neto Oct 06 '20 at 15:36

0 Answers0