在PHP中读取文件的一部分 [英] Read part of a file in PHP

查看:174
本文介绍了在PHP中读取文件的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想读取MP3文件的最后1兆字节,并仅为该文件的该部分计算SHA1校验和.我想要这样做的原因是,当我寻找重复的MP3时,即使是相同的音频文件,标题信息(歌曲标题,专辑等)也可能会有所不同,所以我认为最好进行校验和检查.文件末尾的一部分而不是整个文件的一部分.有有效的方法吗?

I would like to read the last 1 megabyte of a MP3 file and calculate SHA1 checksum for just that part of the file. The reason that I would want this is that when I'm looking for duplicate MP3's, the header info (song title, album etc.) can differ even though it's the exakt same audio file, so I figured I would be better of to checksum a part of the file at the end instead of the whole one. Is there an efficient way of doing this?

推荐答案

您必须使用c包装程序来进行文件操作: fseek 阅读:

You'd have to use the c wrappers for file manipulation: fopen, fseek and fread:

$size = 1024 * 1000;
$handle = fopen($file, 'r');
fseek($handle, -$size);
$limitedContent = fread($handle, $size);
$hash = md5($limitedContent);

这篇关于在PHP中读取文件的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆