dqlhsm9820 2015-01-16 02:54
浏览 54
已采纳

在php中获取Zipfile作为字节?

Using php, how can I read a zip file and get its bytes, for example something like

$contents = file_get_contents('myzipfile.zip');
echo $contents;
// outputs: 504b 0304 1400 0000 0800 1bae 2f46 20e0

Thank you!

  • 写回答

2条回答 默认 最新

  • douyou3619 2015-01-16 04:53
    关注

    file_get_contents gets the raw bytes, your echo outputs those raw bytes. If you expect to output a hexadecimal notation of the raw byte contents instead, use bin2hex:

    echo bin2hex($contents);
    

    If you want that arbitrarily grouped with a space every two bytes, you can do something along these lines:

    echo join(' ', str_split(bin2hex($contents), 4));
    

    (Note that this is all rather inefficient, modifying the entire, possibly many megabyte large file in memory. I'm expecting this is just for debugging purposes, so won't go out of my way to write super efficient code.)

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

报告相同问题?