-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.php
36 lines (30 loc) · 933 Bytes
/
upload.php
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
<?php
session_start();
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$user= $_SESSION['name'];
$fp = fopen($tmpName,"r");
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
$fileName = addslashes($fileName);
$dbname="sweet website";
$servername="localhost";
$password="";
$dbuser="root";
$conn= mysqli_connect($servername,$dbuser,$password,$dbname);
$query = "INSERT INTO upload (name, type, size, content,user_uploaded ) VALUES ('$fileName', '$fileType', '$fileSize', '$content','$user')";
if(mysqli_query($conn, $query))
{
echo '<script>alert("File Inserted into Database")</script>';
header("Location:uploadpage.php");
}
else {
echo "Something went wrong<br>".mysqli_error($conn);
}
}
?>