From 959a70c16302c9731a79ac0b5ca022eb9baf840f Mon Sep 17 00:00:00 2001 From: Nate Date: Tue, 20 Oct 2020 13:14:09 -0600 Subject: [PATCH] Devices - Import: Fix file upload. --- app/devices/device_imports.php | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/app/devices/device_imports.php b/app/devices/device_imports.php index b361629819..460c07bf9c 100644 --- a/app/devices/device_imports.php +++ b/app/devices/device_imports.php @@ -66,25 +66,24 @@ //save the data to the csv file if (isset($_POST['data'])) { $file = $_SESSION['server']['temp']['dir']."/devices-".$_SESSION['domain_name'].".csv"; - file_put_contents($file, $_POST['data']); - $_SESSION['file'] = $file; - } - -//copy the csv file - //$_POST['submit'] == "Upload" && - if ( is_uploaded_file($_FILES['ulfile']['tmp_name']) && permission_exists('device_imports')) { - if ($_POST['type'] == 'csv') { - move_uploaded_file($_FILES['ulfile']['tmp_name'], $_SESSION['server']['temp']['dir'].'/'.$_FILES['ulfile']['name']); - $save_msg = "Uploaded file to ".$_SESSION['server']['temp']['dir']."/". htmlentities($_FILES['ulfile']['name']); - //system('chmod -R 744 '.$_SESSION['server']['temp']['dir'].'*'); - unset($_POST['txtCommand']); - $file = $_SESSION['server']['temp']['dir'].'/'.$_FILES['ulfile']['name']; + if (file_put_contents($file, $_POST['data'])) { $_SESSION['file'] = $file; } } +//copy the csv file + //$_POST['submit'] == "Upload" && + if ( is_uploaded_file($_FILES['ulfile']['tmp_name']) && permission_exists('device_import')) { + if ($_POST['type'] == 'csv') { + $file = $_SESSION['server']['temp']['dir']."/devices-".$_SESSION['domain_name'].".csv"; + if (move_uploaded_file($_FILES['ulfile']['tmp_name'], $file)) { + $_SESSION['file'] = $file; + } + } + } + //get the schema - if (strlen($delimiter) > 0) { + if (strlen($delimiter) > 0 && file_exists($_SESSION['file'])) { //get the first line $line = fgets(fopen($_SESSION['file'], 'r')); $line_fields = explode($delimiter, $line); @@ -441,7 +440,6 @@ echo "\n"; echo "\n"; - /* echo "\n"; echo "\n"; echo " ".$text['label-import_file_upload']."\n"; @@ -451,7 +449,6 @@ echo "
\n"; echo "\n"; echo "\n"; - */ echo "\n"; echo "

";