Reputation: 39
I am just new to using php and have been totally stumped for the last several days. I am trying to extract and use the Key-value pairs extracted from multiple arrays in the $_FILES. I am sure this is a ridiculously dumb question but I am stumped. if I run the following code I get the following results.
$exif = exif_read_data('/uploads/'.$file['name'], 0, true);
foreach($_FILES as $file){
echo $file['name'] . " :<br />\n";
foreach ($exif as $key => $section) {
foreach ($section as $name => $val) {
echo "<pre>This is \$name" . $name ."<br>";
echo "<pre>This is \$val" . $val ."<br>";
}
}
}
The following is the output:
Uploaded Image
Image contains headers
Across the Field - LK.jpg :
FILE.FileName: Across the Field - LK.jpg
FILE.FileDateTime: 1361055472
FILE.FileSize: 294785
FILE.FileType: 2
FILE.MimeType: image/jpeg
FILE.SectionsFound: ANY_TAG, IFD0, THUMBNAIL, EXIF
COMPUTED.html: width="700" height="525"
COMPUTED.Height: 525
COMPUTED.Width: 700
COMPUTED.IsColor: 1
COMPUTED.ByteOrderMotorola: 0
COMPUTED.ApertureFNumber: f/9.0
COMPUTED.Copyright: Copyright 2010
IFD0.ImageWidth: 1024
IFD0.ImageLength: 768
IFD0.BitsPerSample: Array
IFD0.PhotometricInterpretation: 2
IFD0.Model: NIKON D300
IFD0.Orientation: 1
IFD0.SamplesPerPixel: 3
IFD0.XResolution: 720000/10000
IFD0.YResolution: 720000/10000
IFD0.ResolutionUnit: 2
IFD0.Software: Adobe Photoshop CS5 Windows
IFD0.DateTime: 2013:01:24 16:33:16
IFD0.Artist: lken
IFD0.Copyright: Copyright 2010
IFD0.Exif_IFD_Pointer: 316
THUMBNAIL.Compression: 6
THUMBNAIL.XResolution: 72/1
THUMBNAIL.YResolution: 72/1
THUMBNAIL.ResolutionUnit: 2
THUMBNAIL.JPEGInterchangeFormat: 642
THUMBNAIL.JPEGInterchangeFormatLength: 0
EXIF.ExposureTime: 1/100
EXIF.FNumber: 9/1
EXIF.ISOSpeedRatings: 400
EXIF.ExifVersion: 0221
EXIF.DateTimeOriginal: 2010:08:15 05:57:17
EXIF.DateTimeDigitized: 2010:08:15 05:57:17
EXIF.ShutterSpeedValue: 6643856/1000000
EXIF.ApertureValue: 633985/100000
EXIF.FocalLength: 1700/100
EXIF.ColorSpace: 65535
EXIF.ExifImageWidth: 700
EXIF.ExifImageLength: 525
For brevity sake I left out the data from the second photo.
The following is the output of $_FILES:
Array
(
[userfile] => Array
(
[name] => Across the Field - LK.jpg
[type] => image/jpeg
[tmp_name] => C:\wamp\tmp\php223.tmp
[error] => 0
[size] => 294785
)
[userfile1] => Array
(
[name] => autumn-panorama - lk.jpg
[type] => image/jpeg
[tmp_name] => C:\wamp\tmp\php224.tmp
[error] => 0
[size] => 106349
)
)
I have looked on every site and in every book I can find to find how to access the name value pairs (such as IFD0.ImageWidth: 1024 and IFD0.ImageLength: 768 ) so I can set restrictions on upnload sizes etc.
I am now very confused and will appreciate any help or direction. Resources are especially appreciated. Thank you.
Upvotes: 1
Views: 4056
Reputation: 1960
Well, that code snippet already does the job, hence for your first file, you should be able to do the below.
$exif = exif_read_data($_FILES['userfile']['tmp_name'], 0, true);
if (isset($exif['IFD0']['ImageWidth']) && isset($exif['IFD0']['ImageLength']))
{
// good to go!
$width = $exif['IFD0']['ImageWidth'];
$height = $exif['IFD0']['ImageLength'];
}
else
{
// size data not present, fallback onto something else
return;
}
Now, with that said, you should not trust the exif data to do your constraint validation! Exif data are metadata. They can be spoofed/injected easily, or not be there at all. Instead do an analysis of the actual image data, by firstly checking file size itself, and then using getimagesize() for example. See http://www.php.net/manual/en/function.getimagesize.php
Upvotes: 1