From: Andrew Dolgov Date: Fri, 19 Aug 2016 15:14:22 +0000 (+0300) Subject: import_export: better error message if upload failed X-Git-Tag: 17.1~49 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=1a322ff3dfb47a73f52f4076b9d73601999c573e;p=tt-rss.git import_export: better error message if upload failed --- diff --git a/include/functions2.php b/include/functions2.php index dceea507..7e1171b7 100644 --- a/include/functions2.php +++ b/include/functions2.php @@ -2449,4 +2449,20 @@ return $tmp; } + + function get_upload_error_message($code) { + + $errors = array( + 0 => __('There is no error, the file uploaded with success'), + 1 => __('The uploaded file exceeds the upload_max_filesize directive in php.ini'), + 2 => __('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'), + 3 => __('The uploaded file was only partially uploaded'), + 4 => __('No file was uploaded'), + 6 => __('Missing a temporary folder'), + 7 => __('Failed to write file to disk.'), + 8 => __('A PHP extension stopped the file upload.'), + ); + + return $errors[$code]; + } ?> diff --git a/plugins/import_export/init.php b/plugins/import_export/init.php index 7c628909..491216e0 100644 --- a/plugins/import_export/init.php +++ b/plugins/import_export/init.php @@ -425,34 +425,35 @@ class Import_Export extends Plugin implements IHandler { print "
"; if ($_FILES['export_file']['error'] != 0) { - print_error(T_sprintf("Upload failed with error code %d", - $_FILES['export_file']['error'])); - return; - } + print_error(T_sprintf("Upload failed with error code %d (%s)", + $_FILES['export_file']['error'], + get_upload_error_message($_FILES['export_file']['error']))); + } else { - $tmp_file = false; + $tmp_file = false; - if (is_uploaded_file($_FILES['export_file']['tmp_name'])) { - $tmp_file = tempnam(CACHE_DIR . '/upload', 'export'); + if (is_uploaded_file($_FILES['export_file']['tmp_name'])) { + $tmp_file = tempnam(CACHE_DIR . '/upload', 'export'); - $result = move_uploaded_file($_FILES['export_file']['tmp_name'], - $tmp_file); + $result = move_uploaded_file($_FILES['export_file']['tmp_name'], + $tmp_file); - if (!$result) { - print_error(__("Unable to move uploaded file.")); + if (!$result) { + print_error(__("Unable to move uploaded file.")); + return; + } + } else { + print_error(__('Error: please upload OPML file.')); return; } - } else { - print_error(__('Error: please upload OPML file.')); - return; - } - if (is_file($tmp_file)) { - $this->perform_data_import($tmp_file, $_SESSION['uid']); - unlink($tmp_file); - } else { - print_error(__('No file uploaded.')); - return; + if (is_file($tmp_file)) { + $this->perform_data_import($tmp_file, $_SESSION['uid']); + unlink($tmp_file); + } else { + print_error(__('No file uploaded.')); + return; + } } print "