From 8e668a930c7f04d8b29b04539a8ab2c677796f88 Mon Sep 17 00:00:00 2001 From: phl0 Date: Sun, 10 Dec 2023 22:27:20 +0100 Subject: [PATCH] Check file/dir permissions prior to LoTW download --- application/controllers/Lotw.php | 20 +++++++++++++++++--- application/views/lotw/import.php | 9 ++++++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/application/controllers/Lotw.php b/application/controllers/Lotw.php index ff8dfb08..a328824a 100644 --- a/application/controllers/Lotw.php +++ b/application/controllers/Lotw.php @@ -746,10 +746,24 @@ class Lotw extends CI_Controller { $lotw_url .= "&qso_owncall=".$this->input->post('callsign'); } - file_put_contents($file, file_get_contents($lotw_url)); + if (is_writable(dirname($file)) && (!file_exists($file) || is_writable($file))) { + file_put_contents($file, file_get_contents($lotw_url)); - ini_set('memory_limit', '-1'); - $this->loadFromFile($file); + ini_set('memory_limit', '-1'); + $this->loadFromFile($file); + } else { + if (!is_writable(dirname($file))) { + $data['errormsg'] = 'Directory '.dirname($file).' is not writable!'; + } else if (!is_writable($file)) { + $data['errormsg'] = 'File '.$file.' is not writable!'; + } + $this->load->model('Stations'); + $data['callsigns'] = $this->Stations->callsigns_of_user($this->session->userdata('user_id')); + + $this->load->view('interface_assets/header', $data); + $this->load->view('lotw/import', $data); + $this->load->view('interface_assets/footer'); + } } else { diff --git a/application/views/lotw/import.php b/application/views/lotw/import.php index c1cab83e..fd9ffa5b 100644 --- a/application/views/lotw/import.php +++ b/application/views/lotw/import.php @@ -2,10 +2,17 @@

-

+ + + +
+ load->view('layout/messages'); ?> @@ -60,4 +67,4 @@
- \ No newline at end of file +