-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload1.php
More file actions
82 lines (75 loc) · 2.28 KB
/
Copy pathupload1.php
File metadata and controls
82 lines (75 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<style>
#text {
margin: 10px;
}
</style>
</head>
<div class="w3-bar w3-black">
<a href="projectLinks.html" class="w3-bar-item w3-button">Home</a>
<a href="upload1.php" class="w3-bar-item w3-button">Upload</a>
<a href="searchFiles.html" class="w3-bar-item w3-button">Search</a>
<a href="viewFile1.php" class="w3-bar-item w3-button">View</a>
</div>
<div id="text">
Select a file and click upload to contribute to our user generated file database!<br><br> <b>NOTE:</b> Users <b>DO NOT</b> have to enter a name to upload a file. Leave the user section empty if you wish to remain anonymous.<br><br>
</div>
<div id="form">
<?php
echo <<<_END
<html><head><style>#form1{padding: 3px; margin: 10px; align: center;} #form2{padding: 3px; margin: 10px; align: center;}</style><title>PHP Form Upload</title></head><body>
<center><form method='post' action='upload1.php' enctype='multipart/form-data' id="form1"></center>
User:
<input type = "text" name="user" id="form2">
Select File: <input type='file' name='file[]' multiple id="file">
<input type='submit' value='Upload' />
</form></center>
_END;
// This is a form that uploads a file to the server and updates the database with a link to that
// file
$myFile = $_FILES["file"];
$fileCount = count($myFile["name"]);
$host = "";
$username = "";
$password = "";
$db = mysql_connect($host, $username, $password);
mysql_select_db($username, $db);
$filename = $_GET["filename"];
$id = $_GET["id"];
$user = $_POST["user"];
//$filetype = $_GET["filetype"];
if ($_FILES)
{
// Define file directory
define(UPLOAD_DIR,"");
for ($i =0; $i < $fileCount; $i++) {
$type = $myFile["type"][$i];
$name = $myFile["name"][$i];
if (!file_exists(UPLOAD_DIR . $name))
{
$sql = "INSERT INTO project(filename,user,filetype,id) VALUES('$name','$user','$type','$id')";
move_uploaded_file($_FILES['file']['tmp_name'][$i], $name);
$result = mysql_query($sql);
echo "<br />Uploaded '$name'<br>";
}
else
{
echo "Rename" . $name . "file and try again<br>";
}
}
}
echo "</body</html>";
?>
</div>
</div>
<div>
<script>
function myFunction() {
alert("Files Uploaded");
}
</script>
</div>
</html>