title: How to Upload text, pdf, doc, zip file via PHP file upload to MySQL
body: <p>I just implemented an image upload to MySQL via PHP. But i want to upload text, pdf, doc, zip file to MySQL. This is my code. How to change it ?</p>
  
  <pre><code>// uploadAction.php
  
  mysql_connect("localhost", "root", "1989") 
  
  or die(mysql_error());
  
  mysql_select_db("uploadfile") or die(mysql_error());
  
  
  $sql_id = "SELECT (MAX(id)+1) as \"result\" FROM save";
  
  $rs_id = mysql_query($sql_id);
  
  $row_id = mysql_fetch_assoc($rs_id);
  
  $id = $row_id['result'];
  
  if($id == null)
  
  $id = 1;    
  
  $newName = '';  
  
  $file = $_FILES['photo']['name'];
  
  if ((($_FILES["photo"]["type"] == "image/gif")||
  
  ($_FILES["photo"]["type"] == "image/jpeg")||
  
  ($_FILES["photo"]["type"] == "image/pjpeg"))
  
  &amp;&amp; ($_FILES["photo"]["size"] &lt; 200000))
  {
  
  if ($_FILES["photo"]["error"] &gt; 0)
  
      echo "Return Code: " . $_FILES["photo"]["error"] . "&lt;br /&gt;";
  
    else{  
  
        $newName = "$id.".basename($_FILES["photo"]["type"]);
  
        move_uploaded_file($_FILES["photo"]["tmp_name"], "images/" . $newName);
  
        }
  
  } 
  
  else
  
    {
  
    echo "Invalid file";
  
    }
  
  $queryUser = "INSERT INTO save VALUES(NULL, \"$newName\")";
  
  $insert = mysql_query($queryUser);
  
  if(!$insert){
  
      echo mysql_error().'Upload Fail';
  
    }else {
  
      echo "&lt;script&gt;alert('Upload Sccessful');";
  
      echo 'window.location="index.php";&lt;/script&gt;';
  }
  </code></pre>
  
  <p>Database SQL</p>
  
  <pre><code>CREATE TABLE `save` (
  
    `id` int(255) NOT NULL auto_increment,
  
    `photo` varchar(255) character set utf8 collate utf8_unicode_ci NOT NULL,
  
    PRIMARY KEY  (`id`)
  
  )
  </code></pre>