php - 如何检查文件完整性

标签 php android hash integrity

我正在开发一个需要每隔几分钟下载一些文件的应用。

我使用 php 列出所有文件,然后从 java 获取此列表并检查文件是否存在。 下载后,我需要检查完整性,因为有时下载后,某些文件已损坏。

try{
    String path = ...
    URL url = new URL(path);
    URLConnection conn = url.openConnection();
    conn.setDoOutput(true);         
    conn.setReadTimeout(30000);
    is = conn.getInputStream();
    ReadableByteChannel rbc = Channels.newChannel(is);
    FileOutputStream fos = null;
    fos = new FileOutputStream(local);
    fos.getChannel().transferFrom(rbc, 0, 1 << 24);
    fos.close();
    rbc.close();
} catch (FileNotFoundException e) {
    if(new File(local).exists()) new File(local).delete();
       return false;
} catch (IOException e) {
    if(new File(local).exists()) new File(local).delete();
       return false;
} catch (IOException e) {
    if(new File(local).exists()) new File(local).delete();
       return false;
}

return false;

我可以在 php 和 java 中使用什么来检查文件完整性?

最佳答案

维护 checksum list on your server , 下载文件, generate a checksum of the downloaded file并检查它是否与服务器上的相同。如果是,则您的文件没有问题。

关于php - 如何检查文件完整性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16118463/

相关文章:

c++ - 生成 (void *) 数据的 Hash Key

java - 在 Android 中上传图像和文本文件时上传视频不起作用

php - fatal error : Maximum execution time of 30 seconds exceeded

android - 使用 Windows Azure 推送数据

android - 谷歌登录/登录 Yandex Android 扩展

javascript - 在javascript中使用sortBy按值升序排序散列

arrays - Ruby,创建没有现有数组键值的数组

php - JavaScript 表单验证 - 函数未在提交时运行。

javascript - 如何根据选择输入使用javascript更改页面内容?

android - 如何根据在 ListActivity 中长按的项目设置特定的上下文菜单?