John Davidson

Get creation-time of image or video in windows with php

0 comments
Message:


I have a bunch of image- and video-files and want to sort them by creation-date in Windows. In Windows-Explorer, I see a colum "date" which shows the correct date, all my files for testing are from 2019. But using php, it seems I'm not able to get this date: With filemtime, filectime or fileatime, I only get dates from August 2021.


Where is Windows getting the correct date from and how can I get it, too, in php?



My Answer:
n called "Date created" which shows the creation date of each file. However, I want to retrieve this information programmatically using PHP.

To achieve this, you can use the `filectime()` function in PHP to get the creation time of a file in Windows. Here's an example code snippet that demonstrates how to get the creation time of an image or video file:

php
$filename = 'path/to/your/image_or_video_file.jpg'; // Replace this with the path to your image or video file

if (file_exists($filename)) {
$creation_time = filectime($filename);
echo "Creation time of $filename: " . date("Y-m-d H:i:s", $creation_time);
} else {
echo "File not found";
}


In this code snippet, replace `'path/to/your/image_or_video_file.jpg'` with the actual path to your image or video file. The `file_exists()` function is used to check if the file exists before getting its creation time using `filectime()`. The creation time is then formatted using the `date()` function to display it in a human-readable format.

You can use this code snippet to loop through all your image and video files and retrieve their creation times to sort them accordingly.

Rate this post

5 of 5 based on 9256 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us