· 7 years ago · Nov 28, 2018, 03:06 AM
1<?php
2var_dump($_FILES);
3//db connection
4require 'dbConnect.php';
5//session file
6require_once('../auth.php');
7function uploadList(){
8 $target_path = "/home/nyctelecomm.com/www/mail/upload/";
9 //$_FILE function, grab files
10 $inFile = $_FILES["file"];
11 //Get file name
12 $filename = $inFile["name"];
13 //strip the file extension
14 $filename = preg_replace('/\.[^.]+$/','',$filename);
15 var_dump($_FILES);
16 //grab sessionID which is memberID
17 $memberID = $_SESSION["SESS_MEMBER_ID"];
18 //identify cvs, tested with MS excel in csv format
19 if ($inFile["type"] == "application/octet-stream")
20 {
21 if ($inFile["error"] > 0)
22 {
23 echo "Return Code: " . $inFile['error'] . "<br />";
24 }
25 else
26 {
27 dbConnect();
28 //move_uploaded_file($_FILES["file"],$target_path);
29 move_uploadedfile($_FILES['file']['tmp_name'], $target_path);
30 //chmod ($filename['file'], 0777);
31 mysql_select_db('mailList') or die(mysql_error());
32 //assign temporary name to variable
33 //for insert since tmp_file is the real file
34 //$tmp_name = $inFile["file"];
35 $presql = "CREATE TABLE IF NOT EXISTS `{$memberID}` (id MEDIUMINT AUTO_INCREMENT PRIMARY KEY UNIQUE)";
36 $midsql = "ALTER TABLE `{$memberID}` ADD `{$filename}` VARCHAR(60)";
37 $sql = <<<EOF
38 LOAD DATA LOCAL INFILE '{$inFile}'
39 INTO TABLE `{$memberID}`
40 FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\\''
41 LINES TERMINATED BY "\\r\\n
42 IGNORE 1 LINES ($filename)"
43EOF;
44 var_dump($sql);
45 echo '$sql';
46 mysql_query($presql) or die(mysql_error());
47 mysql_query($midsql) or die(mysql_error());
48 mysql_query($sql) or die(mysql_error());
49 var_dump($sql);
50 echo '$sql';
51 if(mysql_error())
52 {
53 echo(mysql_error());
54 }
55 else
56 {
57 print('Import of campaign emails sucessfull into mysql table.');
58 }
59 }
60 }
61 else
62 {
63 print('Invalid file type. Please make sure it is a text file.');
64 }
65}
66
67//var_dump($_FILES);
68uploadList();
69?>