如何使用php读取/提取上传到html表单的文本文件的值到另一个文本文件?

i have the following HTML, JavaScript and PHP code to upload a text file which has a table and display it in the same page,

HTML:

        <panel action="#" method="post"
  enctype="multipart/form-data">
  <label for="file">Filename:</label>

 <input type="file" name="file" id="file" onchange="return ajaxFileUpload(this);">


 </panel>
<iframe width="300px" height="300px" name="upload_iframe" id="upload_iframe" ></iframe>

JavaScript:

         function ajaxFileUpload(upload_field)
        {


        var filename = upload_field.value;


        upload_field.form.action = 'upload_file.php';
        upload_field.form.target = 'upload_iframe';
        upload_field.form.submit();     


        return true;
        }

PHP:upload_file.php

          <?php
       if ($_FILES["file"]["error"] > 0)
        {
         echo "Error: " . $_FILES["file"]["error"] . "<br>";
         } 
         else
           {

           $filepath = $_FILES["file"]["name"];
             if (file_exists($filepath)) {
          $file = fopen($filepath, 'r');
           echo '<table border=1>';
            while (!feof($file)) {
           $line = fgets($file);
        $first_char = $line[0];
        if ($first_char != '*' && $first_char != '^' && trim($line) != '') {
            if (strstr($line, '|')) {
                $split = explode('|', $line);
                echo '<tr>';
                foreach($split as $line) {
                    echo '<td>'.$line.'</td>';
                }
                echo '</tr>';
            } else {
                echo '<tr><td>'.$line.'</td></tr>';
             }
             }
      }
      echo '</table>';
         } else {
       echo 'the file does not exist';
      }
      }
       ?> 

Now, i have the following php code to read/extract the file contents and display it in another text file, but i cannot get the output with this code. This code works fine when i tried to read/extract the values form an input in html page, am i thinking in the right direction ? how can i achieve this?

PHP:

 file_put_contents($file, "
 File Contents: ", FILE_APPEND | LOCK_EX);
//$ret = file_put_contents($file, $_POST['file'], FILE_APPEND | LOCK_EX);

ajaxFileUpload cannot send a $_FILESvariable (only with exporer or old browsers)

I sugest you to Upload your file with normal file input. You don't need copy the uploaded file to a directory after sent form.

Only get the temporany file contents with file_get_contents of $_FILES["file"]["tmp_name"];