我已经做了大约4个小时了。我试了好几件事,我会在提问后解释。
我有来自JPG的所有EXIF数据(如下所列)
我想做的是用一个新名称将JPG重新保存到另一个文件夹中。这个新名称应该是去掉"GCM_TAG"后的$data["EXIF"]["UserComment"]。这是在拍摄照片之前在仓库扫描的条形码。
我没有收到任何错误,也没有收到任何警告,但图像从未显示。如果我将代码更改为没有$条形码,那么图像会突然出现。我试过打印$barcode,我试过检查变量的编码是什么,我试着使用fopen()、file_put_contents()和copy(),但都无济于事。每一个都有相同的结果。该文件夹有777权限,我可以很好地使用php添加/删除文件,并在这段代码中进行了测试。如有任何帮助,我们将不胜感激。
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�<� �����修订版v1.2v�e���v1.29#b6#@�眼睛�HFFA00!�����H�!���r��&����j�����j��K��T0�r����LAt@��$z�fR�5.�E�5*I@#$E�+C�W�6.�J��^֑n、 $$$HFD�5屈!C��^A+����x�� �����������������.Bu�r>�2=:<7736.布�r>�
ioy�������r
!'$/$"#*&0./(++&$%%-39<>N</5��qBdddNJ��������:''�E�E�E�,'P�=��R�O�"�EEEEY����@R%0%0%-��������:������P)`��jdpq�Q��������� ��五、�����������������������������������������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
)
)
正如我所看到的,文件名有一个错误(二进制数据可能会损坏array()),copy()只是抛出一个E_WARNING消息,必须添加到error_reporting(E_ALL)中;或error_reporting(E_WARNING);以查看它。