如何在php中比较两个远程文件?

问题描述 投票:0回答:1

我想用php代码比较两个远程文件。两个文件都位于CDN之后。请让我知道是否有人知道如何执行此操作。

php file request remote-server
1个回答
0
投票

您可以比较两个文件的校验和,以查看它们是否包含相同的内容。您可以使用hash_file生成校验和

$file1 = // path to file 1
$file2 = // path to file 2

$hash_file1 = hash_file("sha256", $file1)
$hash_file2 = hash_file("sha256", $file2)

if ($hash_file1 != $hash_file2){

   echo "File content does not match!"
}

参考:How to calculate SHA256 of large files in php

© www.soinside.com 2019 - 2024. All rights reserved.