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

Posted on 2006-04-01
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 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
    LVL 2

    Accepted Solution

    $_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

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    A colleague recently asked me about how to give his client a small part of the web site that could be completely under the client's control.  Since I have done this sort of thing before to add emergency banners to a web site, I decided I would creat…
    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    758 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

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now