Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function connectDB(){
- $host = "localhost";
- $user = "root";
- $pass = "";
- $name = "klaus";
- $conn = mysql_connect($host,$user,$pass) or die("Cannot connect to database");
- mysql_select_db($name) or die("Cannot find database");
- return $conn;
- } $conn = connectDB();
- ?>
- <form method="post" enctype="multipart/form-data">
- <label for="file" id="label">Locate your file here:</label><br /><br />
- <span style="margin-left:10px;"><input type="file" name="file" id="file" /></span>
- <input type="submit" name="submit" value="Save" /><br />
- <select name="cats">
- <option selected="selected">Accounts</option>
- <option>Invoice</option>
- <option>Order</option>
- <option>Deliverables</option>
- </select></form><br /><br />
- <?php
- if (isset($_FILES["file"])) {
- if (($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) {
- if ($_FILES["file"]["error"] > 0) {
- echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
- }
- else {
- echo "Upload: " . $_FILES["file"]["name"] . "<br />";
- echo "Type: " . $_FILES["file"]["type"] . "<br />";
- echo "Size: " . ceil(($_FILES["file"]["size"] / 1024)) . " Kb<br />";
- echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
- if (file_exists("upload/" . $_FILES["file"]["name"])) {
- echo $_FILES["file"]["name"] . " already exists. ";
- }
- else {
- global $conn;
- mysql_query("INSERT INTO Accounts (ID, Filename, Type) VALUES (null,'".$_FILES["file"]["name"]."', '".$_REQUEST['cats']."')");
- move_uploaded_file($_FILES["file"]["tmp_name"], "upload/".$_REQUEST['cats']."/". $_FILES["file"]["name"]);
- echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
- }
- }
- }
- else {
- echo "Invalid file";
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement