简体   繁体   中英

PHP EXIF data not displaying

I have been trying to display some basic EXIF data from a photo with no luck. My code is below. I just need to display a few basic pieces of information. I have EXIF enabled on the server and I know this image has EXIF data in there - but no data shows up with this set up. Can anyone tell me what I am doing wrong here?

$exif_data = exif_read_data("http://www.findexif.com/client/samples/swiss_house.jpg");

        $emake = $exif_data['Make'];
        $emodel = $exif_data['Model'];
        $eexposuretime = $exif_data['ExposureTime'];
        $efnumber = $exif_data['FNumber'];
        $eiso = $exif_data['ISOSpeedRatings'];
        $edate = $exif_data['DateTime'];

    echo "Make: ". $emake . "<br>";
        echo "Model: ". $emodel . "<br>";
        echo "Exp: ". $eexposuretime . "<br>";
        echo "Date: ". $edate . "<br>";
        echo "ISO: ". $eiso . "<br>";

The filename of exif_read_data cannot be an URL.

If you still want to read EXIF data of external image, you need to download it first:

<?php
$imageURL = 'http://www.findexif.com/client/samples/swiss_house.jpg';
$localURL = '/tmp/swiss_house.jpeg';

// Use 'copy' function if you have PHP5
//  and the HTTP stream wrapper enabled on your server.
copy($imageURL, $localURL);

/**
 * This way if you don't have PHP5
$fp = fopen($localURL, 'w');
fwrite($fp, file_get_contents($imageURL));
fclose($fp);
 */

$exif_data = exif_read_data($localURL);

$emake = $exif_data['Make'];
$emodel = $exif_data['Model'];
$eexposuretime = $exif_data['ExposureTime'];
$efnumber = $exif_data['FNumber'];
$eiso = $exif_data['ISOSpeedRatings'];
$edate = $exif_data['DateTime'];

echo 'Make: '. $emake . '<br>';
echo 'Model: '. $emodel . '<br>';
echo 'Exp: '. $eexposuretime . '<br>';
echo 'Date: '. $edate . '<br>';
echo 'ISO: '. $eiso . '<br>';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM