Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Can I get the date a picture was taken from $FILES array?

Posted on 2006-04-01
Medium Priority
Last Modified: 2012-06-21
Dear experts

I am working on an image file upload script that attempts to read the date the image was taken from the uploaded file array.

I found the 'filemdate' function on php.net and attempted to use it with the following results:

With filemdate($_FILES['ImgFile'][tmp_name]) this just returns the current date (I'm guessing because it was modified when uploaded to the temp dir).

With filemdate($_FILES['ImgFile'][name] I get: 'Warning: filemtime(): Stat failed for 100_0436.jpg (errno=2 - No such file or directory)'.

Can anyone help?

Question by:JasLane

Accepted Solution

CaveyCoUk earned 750 total points
ID: 16353984
$_FILES['ImgFile'][name] is literally the filename of the file on the clients computer (so Bob.jpg)

$_FILES['ImgFile'][tmp_name] is where PHP temporarially stores the file and is going to be not very old.

If you do

$exif_data = exif_read_data ($_FILES['ImgFile'][tmp_name]);

The time the photo was taken should be stored at $exif_data['FileDateTime'] as a Unix time stamp (or it is on all my photos), but it is conceivable that this information wont exist in certain cases.  

It is also stored in $exif_data['DateTime'] as a proper date by my digital camera, BUT I found this was removed by Photoshop when saving for web, so it may not be as reliable as 'FileDateTime'.  

Author Comment

ID: 16442952
Thanks for clearing that up CaveyCoUk. The $exif_data doesn't work in all cases but is the best fit for my problem. Thanks!

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question