Skip to content
Permalink
Browse files

Better visual feedback for file upload errors. Thanks to Gavin for pr…

…oviding the patch.
  • Loading branch information...
mphasize committed Aug 30, 2011
1 parent 646417f commit c329d636bdf2d81d04123d4d85806fb6a2e46ef7
Showing with 55 additions and 30 deletions.
  1. +4 −0 admin/css/iframe.css
  2. +13 −8 admin/js/jquery.JSONeditor.js
  3. +38 −22 admin/php/upload.php
@@ -72,6 +72,7 @@ body {
font-size: 15px;
overflow: hidden;
padding: 10px;
font: 15px/20px "Lucida Grande", Lucida, Verdana, sans-serif;
color: white;
}

@@ -112,4 +113,7 @@ input[type=file] {
font-size: 15px;
}

.error {
color: #D00;
}

@@ -235,14 +235,19 @@
'node' : $(event.target).data('node'),
'source' : $(event.target).data('source')
}, function (data) {
var el = document.getElementById(data.node);
$(el).removeAttr('readonly').val(data.value).attr('readonly', 'readonly');
$(".rr_filedialog",el.parentNode).remove();
$(el).prev().get(0).title = data.value;
var instance = my.getInstance(el);
my.updateJSONValue(instance.rrJson, data.path, data.value);
instance.rrOptions.onChange(el);
instance.rrOptions.onSaveFinished();
var $error = $(".rr_filedialog iframe").contents().find(".error");
if ($error.length > 0) {
$(".btn-clear-file,p").hide();
} else {
var el = document.getElementById(data.node);
$(el).removeAttr('readonly').val(data.value).attr('readonly', 'readonly');
$(".rr_filedialog",el.parentNode).remove();
$(el).prev().get(0).title = data.value;
var instance = my.getInstance(el);
my.updateJSONValue(instance.rrJson, data.path, data.value);
instance.rrOptions.onChange(el);
instance.rrOptions.onSaveFinished();
}
});
} else {
$(event.target).data('loadFired', true);
@@ -9,6 +9,7 @@


<?php
$error = '';
if (!empty($_FILES) && isset($_REQUEST['source'])) {
$filename = $_REQUEST['source'];
$filename = substr($filename, 0, (strpos($filename, '?')));
@@ -19,35 +20,50 @@
$accepted = explode(',', strtolower($_REQUEST['accept']));
$ext = substr($file['name'], strrpos($file['name'], '.') + 1);
if (!in_array(strtolower($ext), $accepted)) {
die('Filetype not accepted');
$error = 'Filetype not accepted.';
}
}
$path = explode('_', $item);
$itemname = $path[sizeof($path) - 1];
$obj = $fonts;
$i = 0;
foreach ($path AS $name) {
if ($name != $itemname) {
if (is_numeric($name)) {
$obj = $obj[$name];
if ($error == '') {
$path = explode('_', $item);
$itemname = $path[sizeof($path) - 1];
$obj = $fonts;
$i = 0;
foreach ($path AS $name) {
if ($name != $itemname) {
if (is_numeric($name)) {
$obj = $obj[$name];
} else {
$obj = $obj->$name;
}
} else {
$obj = $obj->$name;
//echo $itemname;
//echo var_dump($obj);
$obj->$itemname = $file['name'];
if (!is_dir('../' . $_REQUEST['folder'])) {
mkdir('../' . $_REQUEST['folder']);
}
if (!move_uploaded_file($file['tmp_name'], '../' . $_REQUEST['folder'] . '/' . $file['name'])) {
$error = 'Failed to save the file!';
}
}
} else {
//echo $itemname;
//echo var_dump($obj);
$obj->$itemname = $file['name'];
if (!is_dir('../' . $_REQUEST['folder'])) {
mkdir('../' . $_REQUEST['folder']);
}
move_uploaded_file($file['tmp_name'], '../' . $_REQUEST['folder'] . '/' . $file['name']);
//echo 'Done';
}
}
} else {
$error = 'Failed to upload the file!';
}
}
file_put_contents('../' . $filename, json_encode($fonts));
echo 'ok';
if ($error == '') {
file_put_contents('../' . $filename, json_encode($fonts));
echo 'ok';
}
} else if (empty($_FILES) && empty($_POST) && isset($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
$error = 'The file is too big, maximum allowed upload size is '.ini_get('post_max_size').'.';
}
if ($error != '') {
echo '<div class="error">'.$error.'</div>';
} else {
?>

@@ -69,4 +85,4 @@

<?php } ?>
</body>
</html>
</html>

0 comments on commit c329d63

Please sign in to comment.
You can’t perform that action at this time.