title: How to retrieve uploaded files using php
body: <p>Ok. I have searching on this site Since August 24 2011.(not that it matters) for a way to display files that have been uploaded by a user. I have my form on the admin side and everything is working fine. I also have a table displaying whatever the user has filled in the form which also works. But I can not view the file or its name on the table.</p>
  
  <p>My database table has a primary id auto_increment int(11) unsigned.</p>
  
  <p>Here is the code I wrote:</p>
  
  <pre><code>//This gets all the other information from the form 
  $company=$_POST['company']; 
  $location=$_POST['location'];
  $pic=($_FILES['userfile']['name']);
  
  $query = "INSERT INTO user_DB VALUES ('','$company', '$location', '$userfile' )";
  
  //target to the path of my files
  $target_path = "uploads/post_id/";
  if(!is_dir($target_path)) mkdir($target_path);
  $uploadfile = $target_path . basename($_FILES['userfile']['name']);
  
  //Move the uploaded file to $taget_path
  (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile));
  </code></pre>
  
  <p>On the form which you fill in the details I have the following:</p>
  
  <pre><code>&lt;tr&gt;
  &lt;td&gt;&lt;label for="company_name"&gt;Company Name&lt;/label&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type="text" name="company" id="company" value="" size="38" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;label for="location"&gt;Location&lt;/label&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type="text" name="location" id="location" value="" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Upload a File:&lt;/td&gt;
  &lt;td&gt;&lt;input name="userfile" id="userfile" type="file" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>The table which is on the front end that displays the query results looks like this, just the file feild.</p>
  
  <pre><code>echo "&lt;td&gt;";
  echo "&lt;a href=../admin/uploads/post_id/&gt; $row'userfile'&lt;/a&gt;";
  echo "&lt;/td&gt;";
  </code></pre>
  
  <p>So as you can see I am trying to get the file name as well as the file itself. If its a pdf/ jpg/doc I should be able to view/download it when I click the link.</p>
  
  <p>Ant ideas ...</p>