duanhan7001 2013-06-04 01:11
浏览 51
已采纳

使用php提取文件的元数据

There are many file formats nowadays(audio,video,image,text).I wish to write a php code that can get me the metadata of the file irrespective of its format.

To get the basic metadata(filename,filesize,filetype and last modified date),one may use the filesystem API:

<input type="file" id="files" name="files[]" multiple />
<output id="list"></output>

<script>
  function handleFileSelect(evt) {
    var files = evt.target.files; // FileList object

    // files is a FileList of File objects. List some properties.
    var output = [];
    for (var i = 0, f; f = files[i]; i++) {
    output.push('<li><strong>', escape(f.name), '</strong> (', f.type || 'n/a', ') - ',
                 f.size, ' bytes, last modified: ',
                 f.lastModifiedDate ? f.lastModifiedDate.toLocaleDateString() : 'n/a',
                 '</li>');
    }
    document.getElementById('list').innerHTML = '<ul>' + output.join('') + '</ul>';
  }
  document.getElementById('files').addEventListener('change', handleFileSelect, false);
</script>

But,I wish to extract every damn possible thing I can manage to extract from the file(every possible metadata).

Ex: For a jpg image,on extracting its metadata,i get(using exif tags):

FILE.FileName: idfo1.jpg 
FILE.FileDateTime: 1369637595 
FILE.FileSize: 126948 
FILE.FileType: 2  
FILE.MimeType: image/jpeg 
FILE.SectionsFound: ANY_TAG, IFD0, EXIF 
COMPUTED.html: width="915" height="1246" 
COMPUTED.Height: 1246 
COMPUTED.Width: 915 
COMPUTED.IsColor: 1 
COMPUTED.ByteOrderMotorola: 1 
COMPUTED.ApertureFNumber: f/2.6 
COMPUTED.UserComment:  
IFD0.ImageWidth: 2048 
IFD0.ImageLength: 1536 
IFD0.Make: SAMSUNG 
IFD0.Model: GT-S5830 
IFD0.Software: S5830DXKPD 
IFD0.DateTime: 2012:06:06 10:18:24 
IFD0.YCbCrPositioning: 1 
IFD0.Exif_IFD_Pointer: 2232 
IFD0.UndefinedTag:0xEA1C: ê 
EXIF.ExposureTime: 1/229 
EXIF.FNumber: 26/10 
EXIF.ExposureProgram: 3 
EXIF.ISOSpeedRatings: 50 
EXIF.ExifVersion: 0220 
EXIF.DateTimeOriginal: 2012:06:06 10:18:24 
EXIF.DateTimeDigitized: 2012:06:06 10:18:24    
EXIF.MaxApertureValue: 30/10 
EXIF.MeteringMode: 3 
EXIF.Flash: 0 
EXIF.FocalLength: 355/100 
EXIF.UserComment:  
EXIF.ColorSpace: 1 
EXIF.ExifImageWidth: 2048 
EXIF.ExifImageLength: 1536 
EXIF.ExposureMode: 0 
EXIF.WhiteBalance: 0 
EXIF.SceneCaptureType: 0 
EXIF.UndefinedTag:0xEA1C: ê

If possible,I wish to get even the geotagging data.

Similarly,for video and audio type files,I wish to get the:

  • Bitrates(Audio and Video)
  • Duration
  • File Create Date
  • Comments
  • Frame Dimensions etc.

Is there any php or javascript code which can do this directly for me?

  • 写回答

2条回答 默认 最新

  • doushansu9012 2013-06-04 01:26
    关注

    NO, there's no such a thing! You have to write your own code, because there are thousands of formats of audio & video, different codecs, different compression, modes, etc. You have to write your own code for each of them.

    For example, based on codec used, video AVI file may contain a lot of different meta-data - depending of codec (there are hundreds of them).

    Probably you need a lot of experience and months of coding and testing but there's certainly no quick solution.

    You can probably find some basic tools but nothing can find every damn possible thing in every file-type you may use.

    If I'm wrong and you can find some library to do that, please share, but logic says that what you want doesn't exist.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 运筹学中在线排序的时间在线排序的在线LPT算法
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧