/    Sign up×
Community /Pin to ProfileBookmark

Uploading image and reading the EXIF information @ the same time

Hi everyone!

I’ve got an upload script that works great. The only thing is, I want to read the EXIF information on each image I upload so I can tell the user “When the image was taken” and “What camera was used” …

… I tried reading that info from the TMP file, but it doesn’t store it or at least I can’t get it using the exif_read_data() function. I got the exif_read_data() function working for a file I uploaded via FTP straight on to the server but when I’m uploading the files via PHP I can’t seem to get the info.

Can some one tell me what I need to do to be able to read the EXIF information and upload the image at the same time?

Sincerely,
Magnus

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@jasonahouleJan 29.2008 — Have you tried to write the file to wherever you want it and then read the data?
Copy linkTweet thisAlerts:
@trymbillauthorJan 29.2008 — Yes. I haven't tried it with regular PHP functions, am using a image upload class right now, but the image upload class is based on GD so it shouldn't mater.

Am I suppose to be able to view the information even if I've re-created the image with GD?
Copy linkTweet thisAlerts:
@trymbillauthorJan 30.2008 — This is mainly a bump.

I got it working, but it seems as though it only works for a very few number of images. If I upload an image straight to the server I can read all the EXIF information about it. But if I upload the same image via an upload form in PHP I only get a very limited number of details.

I've tried using a EXIF-READER class and also just plain old exif_read_data() function.

Does any one know how I can accomplish this?
Copy linkTweet thisAlerts:
@jasonahouleJan 30.2008 — Try this:
[code=php]
$temp = $_FILES['photo']['tmp_name'];
$exif = read_exif_data($temp);
print_r($exif);
[/code]

I was able to get this to work for me. Read the data before you manipulate the image.
Copy linkTweet thisAlerts:
@trymbillauthorJan 30.2008 — This is what I've been trying to do. But the only thing I get from this is:

[code=php]Array( [FILE] => Array ( [FileName] => phpIc0kVf [FileDateTime] => 1201702738 [FileSize] => 94120 [FileType] => 2 [MimeType] => image/jpeg [SectionsFound] => ) [COMPUTED] => Array ( [code=html] => width="1066" height="800" [Height] => 800 [Width] => 1066 [IsColor] => 1 ))[/code]

I don't get the information I really need.
Copy linkTweet thisAlerts:
@jasonahouleJan 30.2008 — And you are reading from the temp location (['tmp_name']) before you even touch the image? I don't know why that would be. Here is my simple form.
[code=php]
<?php
if(!empty($_POST['submit'])) {
$uploadDir = ".";
$temp = $_FILES['photo']['tmp_name'];

$exif = read_exif_data($temp);

print_r($exif);
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form action="<?= $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data">
<input type="file" name="photo" />
<input type="submit" name="submit" value="submit"/>
</form>
</body>
</html>
[/code]
Copy linkTweet thisAlerts:
@trymbillauthorJan 30.2008 — Yeah, this works on my server also, no problem.

I'm actually using an upload JAVA script called RAD Upload. I'm using it because then I can upload multiple images at once instead of having to select each and every photo I want to publish to my website.

The images are submitted the same way as they would if they were to go through a HTML form. On the PHP side I call the array with the information about the files with $_FILES['userfile']. I then do this:

[code=php]
$files = array();
foreach ($_FILES['userfile'] as $k => $l) {
foreach ($l as $i => $v) {
if (!array_key_exists($i, $files))
$files[$i] = array();
$files[$i][$k] = $v;
}
}
[/code]


So now I have each and every file in a separate row in the array $files.

Then I just do this:

[code=php]
foreach ($files as $file) {
$tempfile = $file['tmp_name'];
$exif = exif_read_data($_FILES['userfile'], 0, true);
print_r($exif);
}
[/code]


And I only get the information I posted above.

I'm guessing that the RAD Upload JAVA program is messing with the EXIF information but it's the only program out there that supports multiple file uploading this way. You can simply drag the files you want to upload into the browser and it starts uploading with a nice progress bar and everything.

Do you know of any better solution for my multiple file uploading?

Ps. Thanks for your help!
×

Success!

Help @trymbill spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...