duandian8110 2014-05-23 12:40
浏览 69
已采纳

在Windows,Linux和Mac上为同一图像创建不同的哈希值

i am creating Hash values with following code, now what happens is that when i test the hash value on Windows local Xampp server i get hash value which is different for same code that runs on Linux.

  move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $newname);
    "Stored in: " . "upload/" . $_FILES["file"]["name"];
    $image = "upload/" . $newname;
    $sign = md5(file_get_contents($image));

Now i dont know why is this happening. For the same code that i just pasted above.

EDIT: Opening question again. The solution i found worked only for Linux which means linux and windows now give me same hash but when an image is uploaded from Mac(IOS) it is still generating different Hash.

  • 写回答

3条回答 默认 最新

  • dsf323233323332 2014-05-23 13:28
    关注

    Ok i found answer to my question, I still dont know why there are two different hashes been generated for the same code in windows and Linux

    move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $newname); 
        "Stored in: " . "upload/" . $_FILES["file"]["name"];
        $image = "upload/" . $newname;
        $sign = md5(file_get_contents($image));//This is code block that i was implmenting before solution
    

    What i tried here was i replaced my above code with following code

     move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $newname);
            "Stored in: " . "upload/" . $_FILES["file"]["name"];
            $image = "upload/" . $newname;
            $sign = md5_file($image);// Changed here
    

    From this i think Hash values may be same when generated by md5() but if this function accepts file as input then hash values are calculated differently, i dont know if this is a PHP side issue or really OS level issue but if i go on with using md5_file() for generating hash of file i dont get different hash.

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

报告相同问题?

悬赏问题

  • ¥100 求数学坐标画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站