title: Is it possible to upload these files to a MySQL database?
body: <p>In my file upload script, I currently have all the files going to an /upload directory. Is it possible for me to upload it to a database as well as the upload directory so it is easier for me to manage? </p>
  
  <pre><code>&lt;?php
  
  require 'header.php';
  
  ?&gt;
  
  &lt;center&gt;
  &lt;?php
  
  $uniqueid = uniqid();
  $file = $uniqueid. basename( $_FILES["fileToUpload"]["name"]);
  $target_dir = "uploads/$uniqueid";
  $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
  $uploadOk = 1;
  $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
  // Check if image file is a actual image or fake image
  if(isset($_POST["submit"])) {
      $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
      if($check !== false) {
          //echo "File is not an image.";
        //  $uploadOk = 1;
      }
  }
  ?&gt;
  &lt;br&gt;
  &lt;?php
  // Check if file already exists
  if (file_exists($target_file)) {
      echo " Sorry, the file already exists or";
      $uploadOk = 0;
  }
  ?&gt;
  &lt;br&gt;
  &lt;?php
  // Check file size
  if ($_FILES["fileToUpload"]["size"] &gt; 5000000) {
      echo "Sorry, your file is too large.";
      $uploadOk = 0;
  }
  // Allow certain file formats
  if($imageFileType != "jpg" &amp;&amp; $imageFileType != "png" &amp;&amp; $imageFileType != "jpeg"
  &amp;&amp; $imageFileType != "gif" &amp;&amp; $imageFileType != "txt") {
      echo "Sorry, only JPG, JPEG, PNG, GIF and TXT files are allowed.";
      $uploadOk = 0;
  }
  // Check if $uploadOk is set to 0 by an error
  if ($uploadOk == 0) {
      echo "your file was not uploaded correctly. Please try again or contact support!.";
  // if everything is ok, try to upload file
  } else {
      if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
          echo "Your file has been uploaded
          &lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;
           &lt;img src='uploads/$file'&gt;";
      } else {
          echo "Sorry, there was an error uploading your file.";
      }
  }
  ?&gt;
  &lt;/center&gt;
  </code></pre>