title: PHP/HTML - Display Uploaded Files in List
body: <p>I'm trying to create a file sharing site where I can display the links of all uploaded images. Once a user uploads one file, they will be able to both see the files already uploaded and upload another file. However, I'm having two problems at the moment:
  1. I don't know how to re-display the main upload page once a user uploads an image.
  2. I don't know how to dynamically create links based on the files present.</p>
  
  <p>Here is the code that I have so far:</p>
  
  <p><strong>HTML/PHP</strong>
      
      
      
      
      File-Sharing Site
      </p>
  
  <pre><code>&lt;body&gt;
  &lt;h2&gt;File-Sharing Site&lt;/h2&gt;
  &lt;h3&gt;Upload file&lt;/h3&gt;
  &lt;form action="upload_file.php" method="post" enctype="multipart/form-data"&gt;
  Search for file: &lt;br /&gt;
  &lt;input type="file" name="file" id="file" /&gt;
  &lt;input type="submit" name="submit" value="Upload" /&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>PHP</strong></p>
  
  <pre><code>&lt;?php
      $allowedExts = array("jpg", "jpeg", "gif", "png");
      $extension = end(explode(".", $_FILES["file"]["name"]));
      if((($_FILES["file"]["type"] == "image/gif")
      || ($_FILES["file"]["type"] == "image/jpeg")
      || ($_FILES["file"]["type"] == "image/pjpeg"))
      &amp;&amp; ($_FILES["file"]["size"] &lt; 800000)
      &amp;&amp; in_array($extension, $allowedExts))
      {
      if($_FILES["file"]["error"] &gt; 0)
      {
          echo "Error: " . $_FILES["file"]["error"] . "&lt;br /&gt;";
      }
      else
      {
          echo "Upload: " . $_FILES["file"]["name"] . "&lt;br /&gt;";
          echo "Type: " . $_FILES["file"]["type"] . "&lt;br /&gt;";
          echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb&lt;br /&gt;";
          echo "Stored in: " . $_FILES["file"]["tmp_name"];
  
          if (file_exists("upload/" . $_FILES["file"]["name"]))
          {
              echo $_FILES["file"]["name"] . " already exists. ";
          }
          else
          {
              move_uploaded_file($_FILES["file"]["tmp_name"],
              "upload/" . $_FILES["file"]["name"]);
              echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
          }
      }
  }
  else
  {
      echo "Invalid file";
  }
  </code></pre>
  
  <p>?></p>