· 7 years ago · Aug 24, 2018, 11:06 AM
1<?php
2
3//include the file that loads the PhpSpreadsheet classes
4require 'spreadsheet/vendor/autoload.php';
5
6$secret_key = 'ddf9dcbb413630dd650a9615c921b12d1dbe3e203b8f5d4d08bef5e47cd88979';
7$uploaddir = realpath('./') . '/';
8$uploadfile = $uploaddir . basename($_FILES['phyle']['name']);
9$filename = $_POST['prefix'].".csv";
10$key = $_POST['key'];
11$usl = $_POST['usl'];
12
13if ($secret_key == $key) {
14 echo '<pre>';
15 if (move_uploaded_file($_FILES['phyle']['tmp_name'], $uploadfile)) {
16 echo "File is valid, and was successfully uploaded.\n";
17
18 // create directly an object instance of the IOFactory class, and load the xlsx file
19 $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($uploadfile);
20
21 // read excel data and store it into an array
22 $xls_data = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
23
24 // total numbder of rows
25 $nr = count($xls_data)-1;
26
27 // writing rows csv format
28 $handle = fopen($filename, "w");
29 foreach($xls_data as $data) {
30 fputcsv($handle, $data);
31 }
32 fclose($handle) or die("Can't close php://output");
33
34 if(file_exists('./'.$filename)){
35 $file_name_with_full_path = realpath('./'.$filename);
36
37 // send file to the usl
38 $post = array('key' => $secret_key,
39 'phyle' => new CURLFile($file_name_with_full_path));
40
41 $ch = curl_init();
42 curl_setopt($ch, CURLOPT_URL,$usl);
43 curl_setopt($ch, CURLOPT_POST,1);
44 curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
45 curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
46 $result=curl_exec ($ch);
47 curl_close ($ch);
48 //echo $result;
49 }
50
51 } else {
52 echo "Possible file upload attack!\n";
53 }
54
55
56 echo 'Here is some more debugging info:';
57 print_r($_FILES);
58 echo "\n<hr />\n";
59 print_r($_POST);
60 print "</pr" . "e>\n";
61 //echo($nr." has been imported successfully");
62}
63
64
65?>