Read part of a file in PHP

前端 未结 3 1192
醉酒成梦
醉酒成梦 2021-01-24 00:51

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 fo

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-24 01:11

    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);
    

提交回复
热议问题