Question

I've been going at this for about 4 hours now. I've tried several things which I'll explain after the question.

I have all of this EXIF data from the JPG in question (listed below)

What I am trying to do is re-save the JPG into a different folder with a new name. That new name is supposed to be the $data["EXIF"]["UserComment"] after stripping out the "GCM_TAG". This is a barcode that is scanned at a warehouse before the picture is taken.

I am not getting any errors back, I am not getting any warnings back, but the image never shows up. If I change the code to not have the $barcode in it, then suddenly the image shows up. I have tried printing $barcode, I have tried checking what the encoding on the variable is, I have tried using fopen(), file_put_contents() and copy() all to no avail. Each one has the same results. The folder has 777 permissions on it, I can add/remove files using php just fine and have tested that in this code. Any help would be greatly appreciated.

chdir("../test_import_photos");
$directory = getcwd();

echo __FILE__;
print "<br />";
print $directory;
if ($dirhandle = opendir($directory))
{
    while (false !== ($entry = readdir($dirhandle)))
    {
        if($entry == "." || $entry == "..")
        {
            //ignore, its just the folder commands
        }
        else
        {
            $data = exif_read_data($entry,"ANY_TAG",true,false);
            //print "2";
            //print "3";

            $barcode = str_replace("GCM_TAG","",$data["EXIF"]["UserComment"]);

            $filepath = "../test_import_photos_end/X" . $barcode .  ".JPG";
            copy($entry, $filepath);
        }
    }
    closedir($dirhandle);
}


Array(
    [FILE] => Array
    (
        [FileName] => RIMG0089.JPG
        [FileDateTime] => 1385421951
        [FileSize] => 2592157
        [FileType] => 2
        [MimeType] => image/jpeg
        [SectionsFound] => ANY_TAG, IFD0, THUMBNAIL, EXIF, INTEROP
    )

[COMPUTED] => Array
    (
        [html] => width="4000" height="3000"
        [Height] => 3000
        [Width] => 4000
        [IsColor] => 1
        [ByteOrderMotorola] => 1
        [ApertureFNumber] => f/3.5
        [UserComment] => GCM_TAG
        [UserCommentEncoding] => UNDEFINED
        [Copyright] =>                          
        [Thumbnail.FileType] => 2
        [Thumbnail.MimeType] => image/jpeg
    )

[IFD0] => Array
    (
        [ImageDescription] => Exif_JPEG_PICTURE                                              
        [Make] => RICOH      
        [Model] => G700 SE        
        [Orientation] => 1
        [XResolution] => 72/1
        [YResolution] => 72/1
        [ResolutionUnit] => 2
        [Software] => G700SE Firmware
        [DateTime] => 2013:11:25 02:53:04
        [YCbCrPositioning] => 2
        [Copyright] =>                          
        [Exif_IFD_Pointer] => 552
        [UndefinedTag:0xC4A5] => PrintIM0300d   

� �� ''�'�''^'�'�'�' )

[THUMBNAIL] => Array
    (
        [Compression] => 6
        [XResolution] => 72/1
        [YResolution] => 72/1
        [ResolutionUnit] => 2
        [JPEGInterchangeFormat] => 12276
        [JPEGInterchangeFormatLength] => 2724
    )

[EXIF] => Array
    (
        [ExposureTime] => 1/30
        [FNumber] => 350/100
        [ExposureProgram] => 2
        [ISOSpeedRatings] => 320
        [ExifVersion] => 0221
        [DateTimeOriginal] => 2013:11:25 02:53:04
        [DateTimeDigitized] => 2013:11:25 02:53:04
        [ComponentsConfiguration] => 
        [CompressedBitsPerPixel] => 184/100
        [ApertureValue] => 35/100
        [BrightnessValue] => 200/100
        [ExposureBiasValue] => 0/100
        [MaxApertureValue] => 361/100
        [MeteringMode] => 5
        [LightSource] => 0
        [Flash] => 16
        [FocalLength] => 500/100
        [MakerNote] => Ricoh

Rdchp�<� ��� ��Revv1.2v�e�� �v1.29#b6#@�EYE�HFFA00! �����H�!���r��& ����j�����j��K��T0� r���� LAt@��$z�fR�5�E�5*I@#$E�+C�W�6�J��^֑ n,$$$HFD �5Qu!C�� ^A+����x�� �����������������.Bu�r>�2=:<7736.Bu�r>�
ioy�������r

!'$,./$"# *&+0./(+%&$%%-39<;>N<;/5��qBdddNJ��������:\�E�E �E,�,'P?�=��R�O�"�EEEEY����@R%0%0%-��������:������P)`��jdpq�Q��������� ��V�����������������������������������������6E����������������6E��������6E��������������������������������������

[UserComment] => GCM_TAG11800038
        [FlashPixVersion] => 0100
        [ColorSpace] => 1
        [ExifImageWidth] => 4000
        [ExifImageLength] => 3000
        [InteroperabilityOffset] => 1732
        [ExposureMode] => 0
        [WhiteBalance] => 0
        [SceneCaptureType] => 0
        [Sharpness] => 0
    )

[INTEROP] => Array
    (
        [InterOperabilityIndex] => R98
        [InterOperabilityVersion] => 0100
    )

)

Was it helpful?

Solution

As i see there was an error with the filename (the binary data may corrupts the array()) and copy() just throws an E_WARNING message and must be added to error_reporting(E_ALL); or error_reporting(E_WARNING); to see it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top