import_export: better error message if upload failed
This commit is contained in:
parent
a84fb943b4
commit
1a322ff3df
|
@ -2449,4 +2449,20 @@
|
||||||
|
|
||||||
return $tmp;
|
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];
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -425,34 +425,35 @@ class Import_Export extends Plugin implements IHandler {
|
||||||
print "<div style='text-align : center'>";
|
print "<div style='text-align : center'>";
|
||||||
|
|
||||||
if ($_FILES['export_file']['error'] != 0) {
|
if ($_FILES['export_file']['error'] != 0) {
|
||||||
print_error(T_sprintf("Upload failed with error code %d",
|
print_error(T_sprintf("Upload failed with error code %d (%s)",
|
||||||
$_FILES['export_file']['error']));
|
$_FILES['export_file']['error'],
|
||||||
return;
|
get_upload_error_message($_FILES['export_file']['error'])));
|
||||||
}
|
} else {
|
||||||
|
|
||||||
$tmp_file = false;
|
$tmp_file = false;
|
||||||
|
|
||||||
if (is_uploaded_file($_FILES['export_file']['tmp_name'])) {
|
if (is_uploaded_file($_FILES['export_file']['tmp_name'])) {
|
||||||
$tmp_file = tempnam(CACHE_DIR . '/upload', 'export');
|
$tmp_file = tempnam(CACHE_DIR . '/upload', 'export');
|
||||||
|
|
||||||
$result = move_uploaded_file($_FILES['export_file']['tmp_name'],
|
$result = move_uploaded_file($_FILES['export_file']['tmp_name'],
|
||||||
$tmp_file);
|
$tmp_file);
|
||||||
|
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
print_error(__("Unable to move uploaded file."));
|
print_error(__("Unable to move uploaded file."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
print_error(__('Error: please upload OPML file.'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
print_error(__('Error: please upload OPML file.'));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_file($tmp_file)) {
|
if (is_file($tmp_file)) {
|
||||||
$this->perform_data_import($tmp_file, $_SESSION['uid']);
|
$this->perform_data_import($tmp_file, $_SESSION['uid']);
|
||||||
unlink($tmp_file);
|
unlink($tmp_file);
|
||||||
} else {
|
} else {
|
||||||
print_error(__('No file uploaded.'));
|
print_error(__('No file uploaded.'));
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print "<button dojoType=\"dijit.form.Button\"
|
print "<button dojoType=\"dijit.form.Button\"
|
||||||
|
|
Loading…
Reference in New Issue