Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.78 KB | None | 0 0
  1. <?php
  2.  
  3. function connectDB(){
  4.     $host = "localhost";
  5.     $user = "root";
  6.     $pass = "";
  7.     $name = "klaus";
  8.     $conn = mysql_connect($host,$user,$pass) or die("Cannot connect to database");
  9.     mysql_select_db($name) or die("Cannot find database");
  10.     return $conn;
  11. } $conn = connectDB();
  12. ?>
  13.  
  14. <form method="post" enctype="multipart/form-data">
  15.     <label for="file" id="label">Locate your file here:</label><br /><br />
  16.     <span style="margin-left:10px;"><input type="file" name="file" id="file" /></span>
  17.     <input type="submit" name="submit" value="Save" /><br />
  18.  
  19.  
  20. <select name="cats">
  21.     <option selected="selected">Accounts</option>
  22.     <option>Invoice</option>
  23.     <option>Order</option>
  24.     <option>Deliverables</option>
  25. </select></form><br /><br />
  26.  
  27. <?php
  28. if (isset($_FILES["file"])) {
  29.     if (($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) {
  30.         if ($_FILES["file"]["error"] > 0) {
  31.             echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
  32.         }
  33.         else {
  34.             echo "Upload: " . $_FILES["file"]["name"] . "<br />";
  35.             echo "Type: " . $_FILES["file"]["type"] . "<br />";
  36.             echo "Size: " . ceil(($_FILES["file"]["size"] / 1024)) . " Kb<br />";
  37.             echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
  38.  
  39.             if (file_exists("upload/" . $_FILES["file"]["name"])) {
  40.                 echo $_FILES["file"]["name"] . " already exists. ";
  41.             }
  42.             else {
  43.                 global $conn;
  44.                 mysql_query("INSERT INTO Accounts (ID, Filename, Type) VALUES (null,'".$_FILES["file"]["name"]."', '".$_REQUEST['cats']."')");
  45.                 move_uploaded_file($_FILES["file"]["tmp_name"], "upload/".$_REQUEST['cats']."/". $_FILES["file"]["name"]);
  46.                 echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
  47.             }
  48.         }
  49.     }
  50.     else {
  51.         echo "Invalid file";
  52.     }
  53.  }
  54. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement