Skip to content

Commit

Permalink
Added preview on js / directory calcualting on upload
Browse files Browse the repository at this point in the history
  • Loading branch information
copostic committed Jun 6, 2018
1 parent b632d6e commit c1d1f9a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
8 changes: 8 additions & 0 deletions controllers/uploader.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
<?php
function directorySize($directory) {
$size = 0;
foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $file){
$size += $file->getSize();
}
return $size;
}

require_once LIB . 'vendor/fineuploader/php-traditional-server/endpoint.php';
49 changes: 49 additions & 0 deletions public/js/explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,55 @@ $('div.actions > button', $mainSection).on('click', function() {

}
});
} else if (action === 'display') {
$.ajax({
url: 'http://supfile.tk/explorer',
type: 'POST',
data: {action: 'download', path: path},
cache: false,
xhr: function() {
var xhr = new XMLHttpRequest();
xhr.responseType = 'blob';
return xhr;
},
success: function(data) {
if (data != null && navigator.msSaveBlob)
return navigator.msSaveBlob(new Blob([data], {type: data.type}), '');
var blob = new Blob([data], {type: data.type});
var url = window.URL.createObjectURL(blob);
var tag;
if (data.type.split('/')[0] === 'image') {
tag = $("<img src='" + url + "' id='preview'/>");
} else if (data.type === 'application/pdf') {
tag = $('<object height="950" data="' + url + '" type="application/pdf" width="860">\n' +
' <p>It appears you don\'t have a PDF plugin for this browser.\n' +
' No biggie... you can <a href="' + url + '">click here to\n' +
' download the PDF file.</a>\n' +
' </p>\n' +
'</object>');
} else if (data.type.split('/')[0] === 'video') {
tag = $('<video controls src="' + url + '">Woops we ran into an issue ... </video>');
} else if(data.type.split('/')[0] === 'audio'){
tag = $('<audio controls src="' + url + '">Woops we ran into an issue ... </audio>');
}else if(data.type.split('/')[0] === 'text'){
var myReader = new FileReader();
myReader.addEventListener("loadend", function(e){
$('#uploader').html(e.target.result);
});
myReader.readAsText(blob);
}
//TODO: Add it to a modal instead
$("#uploader").append(tag);

/* var a = $("<a style='display: none;'/>");
a.attr("href", url);
$("body").append(a);*/
},
error: function() {

}
});

} else {
$.post('http://supfile.tk/explorer', {action: action, path: path}, function(data) {
getList(data);
Expand Down

0 comments on commit c1d1f9a

Please sign in to comment.