<html>
<head>
<title>Загрузка файлов на сервер</title>
</head>
<body>
<p><b> Форма для загрузки файлов </b></p></h2>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="filename1"><br>
<input type="file" name="filename2"><br>
<input type="submit" name="sbutton" value="Загрузить"><br>
</form>
</body>
</html>
<?php
if ($_POST){
if(is_uploaded_file($_FILES["filename1"]["tmp_name"]))
{
move_uploaded_file($_FILES["filename1"]["tmp_name"], "files/".$_FILES["filename1"]["name"]."file_1");
}
if(is_uploaded_file($_FILES["filename2"]["tmp_name"]))
{
move_uploaded_file($_FILES["filename2"]["tmp_name"], "files/".$_FILES["filename2"]["name"]."file_2");
}
$filepath_1 = "files/".$_FILES["filename1"]["name"]."file_1";
$filepath_2 = "files/".$_FILES["filename2"]["name"]."file_2";
if (filesize($filepath_1) !== filesize($filepath_2))
{
echo "файлы не равны";
exit();
}
$fp1 = fopen($filepath_1, 'r');
$fp2 = fopen($filepath_2, 'r');
$found = 0;
while (1)
{
$ch1 = fgetc($fp1);
$ch2 = fgetc($fp2);
if (feof($fp1) === true) break;
if ($ch1 === $ch2) {
$found = 1;
}
else
{
$found = 2;
}
}
if ($found == 1)
{
echo "файлы равны";
}
if ($found == 2)
{
echo "файлы не равны";
}
}
?>
|