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 对于这个复杂问题的解释说明
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败