我正在通过EXIF数据从JPEG图像中检索f值。为了获得所需的数字,我需要评估表达式。现在我为此使用三行代码。它可以缩短,还是理想的单线?
$fnumber = $exif['FNumber'];
eval("\$fnumber = $fnumber;");
$photo['fnumber'] = $fnumber;
var_export($ exif)的相关内容:
'FileName' => '_80A9888.jpg',
'FileSize' => 487519,
'FileType' => 2,
'MimeType' => 'image/jpeg',
'ExposureTime' => '1/30',
'FNumber' => '4/1',
'ExposureProgram' => 3,
'ISOSpeedRatings' => 125,
'ExifVersion' => '0230',
'ShutterSpeedValue' => '4906891/1000000',
'ApertureValue' => '4/1',
'ExposureBiasValue' => '-1/3',
'MaxApertureValue' => '4/1',
'MeteringMode' => 3,
'Flash' => 16,
'FocalLength' => '70/1',
答案 0 :(得分:3)
你在做什么是非常危险的。代码可以从输入源(jpeg)注入。
<强> !!!不要在这里使用eval()
。 !!! 强>
您需要编写一个评估表达式的小解析器:
// Typical value of fnumber (I obtained from a test JPEG using exif_read_data())
$fnumber = '35/10';
// Split by `/`
$operands = explode('/', $fnumber);
// Divide
$result = $operands[0] / $operands[1];
echo $result;