How to get any type of images creation date and time in php

694 views Asked by At

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.

0

There are 0 answers