-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload.php
More file actions
62 lines (44 loc) · 1.56 KB
/
upload.php
File metadata and controls
62 lines (44 loc) · 1.56 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
<?php
include 'header.php';
if (!isset($_SESSION['id'])) {
echo "You are not logged in!";
exit();
} else {
ini_set('display_errors', 1);
error_reporting(E_ALL);
$db_host = 'db658651383.db.1and1.com';
$db_user = 'dbo658651383';
$db_pwd = 'Xenyx-1832';
$database = 'db658651383';
$table = 'testparty2';
if (!mysql_connect($db_host, $db_user, $db_pwd))
die("Can't connect to database");
if (!mysql_select_db($database))
die("Can't select database");
if (isset($_POST['submit'])) {
$fname = $_FILES['sel_file']['name'];
echo 'upload file name: ' . $fname . ' ';
$chk_ext = explode(".", $fname);
if (strtolower(end($chk_ext)) == "csv") {
$filename = $_FILES['sel_file']['tmp_name'];
$handle = fopen($filename, "r");
$manager = $_SESSION['id'];
while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
$sql = "INSERT into testparty2(ordernumber,ticketName,ticketId,customerName,manager) values('$data[0]','$data[1]','$data[2]','$data[3]','$manager')";
mysql_query($sql) or die(mysql_error());
}
fclose($handle);
echo "Successfully Imported";
} else {
echo "Invalid File";
}
}
}
?>
<h1>Import CSV file</h1>
<form action='<?php echo $_SERVER["PHP_SELF"];?>' method='post' enctype="multipart/form-data">
Import File : <input type='file' name='sel_file' size='20'>
<input type='submit' name='submit' value='submit'>
</form>
<br>
<br>