【问题标题】:Comparing two uploaded files比较两个上传的文件
【发布时间】:2013-08-24 09:22:17
【问题描述】:

我想比较两个上传的文件并显示两个文件中相同的字符串,告知百分比,但我不知道如何处理它。非常感谢任何帮助。下面是我的上传表单。

<p>Choose files to be compared<p>
                    <hr />
                    <form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">                     


                  <!--APC hidden field-->
                      <input type="hidden" name="APC_UPLOAD_PROGRESS" id="progress_key" value="<?php echo $up_id; ?>"/>
                  <!---->

                      <input name="file" type="file" id="file" size="30"/>

                  <!--Include the iframe-->
                      <br />
                      <iframe id="upload_frame" name="upload_frame" frameborder="0" border="0" src="" scrolling="no" scrollbar="no" > </iframe>
                      <br />
                  <!---->


                  <!--APC hidden field-->
                      <input type="hidden" name="APC_UPLOAD_PROGRESS" id="progress_key1" value="<?php echo $up_id; ?>"/>
                  <!---->

                      <input name="file1" type="file" id="file1" size="30"/>

                  <!--Include the iframe-->
                      <br />
                      <iframe id="upload_frame" name="upload_frame" frameborder="0" border="0" src="" scrolling="no" scrollbar="no" > </iframe>
                      <br />
                  <!---->

                      <input name="Submit" type="submit" id="uploadFilesButton" style="width:250px; height:35px; background-color: #003333; color: #ffffff; border-radius: 10px;" value="PlagCheck" />
                    </form>

【问题讨论】:

  • 搜索“php diff”。

标签: php file-upload file-io file-comparison


【解决方案1】:

这篇文章 (How to find extra lines by comparing two files using php?) 可能会有所帮助。因此,请执行以下操作:

  1. file_get_contents(将每个文件内容放入一个字符串)
  2. 将字符串内容拆分为单词数组 (explode(" ", $str);)
  3. 存储要获取百分比的文件的字数(例如 File1)。
  4. 删除 File1 数组中 File2 数组中的所有单词

    foreach($file2array as $word){if (in_array($word, $file1array)){unset($file1array[$word])}}

  5. 在这个阶段获取 File1 的数组长度。

  6. 使用第 3 步和第 5 步中的数字获取百分比。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多