diff --git a/tinyfilemanager.php b/tinyfilemanager.php
index 6b5c3aa..619f161 100644
--- a/tinyfilemanager.php
+++ b/tinyfilemanager.php
@@ -187,6 +187,35 @@ unset($p, $use_auth, $iconv_input_encoding, $use_highlightjs, $highlightjs_style
/*************************** ACTIONS ***************************/
+//AJAX Request
+if (isset($_POST['ajax']) && !FM_READONLY) {
+
+ //search : get list of files from the current folder
+ if(isset($_POST['type']) && $_POST['type']=="search") {
+ $dir = $_POST['path'];;
+ $response = scan($dir);
+ echo json_encode($response);
+ }
+
+ //Send file to mail
+ if (isset($_POST['type']) && $_POST['type']=="mail") {
+ $isSend = send_mail($_POST['path'],$_POST['file'],'ccpprogrammers@gmail.com','Hello Word');
+ echo $isSend;
+ }
+
+ //backup files
+ if(isset($_POST['type']) && $_POST['type']=="backup") {
+ $file = $_POST['file'];
+ $path = $_POST['path'];
+ $date = date("dMy-His");
+ $newFile = $file.'-'.$date.'.bak';
+ copy($path.'/'.$file, $path.'/'.$newFile) or die("Unable to backup");
+ echo "Backup $newFile Created";
+ }
+
+ exit;
+}
+
// Delete file / folder
if (isset($_GET['del']) && !FM_READONLY) {
$del = $_GET['del'];
@@ -865,6 +894,7 @@ if (isset($_GET['view'])) {
?>
+
@@ -1471,6 +1502,79 @@ function fm_enc($text)
return htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
}
+/**
+ * This function scans the files folder recursively, and builds a large array
+ * @param string $dir
+ * @return json
+ */
+function scan($dir){
+ $files = array();
+ // Is there actually such a folder/file?
+ if(file_exists($dir)){
+ foreach(scandir($dir) as $f) {
+ if(!$f || $f[0] == '.') {
+ continue; // Ignore hidden files
+ }
+
+ if(is_dir($dir . '/' . $f)) {
+ // The path is a folder
+ $files[] = array(
+ "name" => $f,
+ "type" => "folder",
+ "path" => $dir . '/' . $f,
+ "items" => scan($dir . '/' . $f), // Recursively get the contents of the folder
+ );
+ } else {
+ // It is a file
+ $files[] = array(
+ "name" => $f,
+ "type" => "file",
+ "path" => $dir . '/' . $f,
+ "size" => filesize($dir . '/' . $f) // Gets the size of this file
+ );
+ }
+ }
+ }
+ return $files;
+}
+
+/**
+ * Send email with file attached
+ * @param string $msg, $to, $p
+ */
+function send_mail($path,$filename, $mailto, $message) {
+ $file = $path.'/'.$filename;
+ $content = file_get_contents( $file);
+ $content = chunk_split(base64_encode($content));
+ $uid = md5(uniqid(time()));
+ $name = basename($file);
+
+ // header
+ $header = "From: H3K File Manager
\r\n";
+ $header .= "Reply-To: ".$mailto."\r\n";
+ $header .= "MIME-Version: 1.0\r\n";
+ $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
+
+ // message & attachment
+ $subject = "File has attahced";
+ $nmessage = "--".$uid."\r\n";
+ $nmessage .= "Content-type:text/plain; charset=iso-8859-1\r\n";
+ $nmessage .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
+ $nmessage .= $message."\r\n\r\n";
+ $nmessage .= "--".$uid."\r\n";
+ $nmessage .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n";
+ $nmessage .= "Content-Transfer-Encoding: base64\r\n";
+ $nmessage .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
+ $nmessage .= $content."\r\n\r\n";
+ $nmessage .= "--".$uid."--";
+
+ if (mail($mailto, $subject, $nmessage, $header)) {
+ return true; // Or do something here
+ } else {
+ return false;
+ }
+}
+
/**
* Save message in session
* @param string $msg
@@ -1590,6 +1694,9 @@ function fm_get_file_icon_class($path)
case 'csv':
$img = 'fa fa-file-text-o';
break;
+ case 'bak':
+ $img = 'fa fa-clipboard';
+ break;
case 'doc': case 'docx':
$img = 'fa fa-file-word-o';
break;
@@ -1828,6 +1935,8 @@ function fm_show_nav_path($path)
+
+
@@ -1903,7 +2012,7 @@ body {margin:0 30px;margin-top: 45px;}.logo{color:#0df70d;float:left;font-size:2
.preview-video{position:relative;max-width:100%;height:0;padding-bottom:62.5%;margin-bottom:10px}.preview-video video{position:absolute;width:100%;height:100%;left:0;top:0;background:#000}
.compact-table{border:0;width:auto}.compact-table td,.compact-table th{width:100px;border:0;text-align:center}.compact-table tr:hover td{background-color:#fff}
.filename{max-width:420px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
-.break-word{word-wrap:break-word}.break-word.float-left a{color:#fff}.break-word+.float-right{padding-right:30px;}.break-word+.float-right>a{color:#fff;font-size:1.2em;margin-right:4px;}
+.break-word{word-wrap:break-word}.break-word.float-left a{color:#fff}.break-word+.float-right{padding-right:30px;position:relative;}.break-word+.float-right>a{color:#fff;font-size:1.2em;margin-right:4px;}
.modal{display:none;position:fixed;z-index:1;padding-top:100px;left:0;top:0;width:100%;height:100%;overflow:auto;background-color:#000;background-color:rgba(0,0,0,.4)}
.modal-content{background-color:#fefefe;margin:auto;padding:20px;border:1px solid #888;width:80%}
.close{color:#aaa;float:right;font-size:28px;font-weight:700}.close:focus,.close:hover{color:#000;text-decoration:none;cursor:pointer}
@@ -1914,17 +2023,14 @@ body {margin:0 30px;margin-top: 45px;}.logo{color:#0df70d;float:left;font-size:2
.main-nav{position:fixed;top:0;left:0;padding:10px 30px;padding-left:1px;width:100%;background:#585858;color:#fff;border:0;}
.login-form {width:320px;text-align:center;margin:0 auto;}
.login-form label,.path.login-form input {padding:5px;margin:10px}.footer-links{background:transparent;border:0}
+input[type=search]{position: absolute;height: 26px;right: 100%;top: -4px;margin-right: 10px;width: 200px;border-radius: 2px;border: 0;}
.modalDialog{position:fixed;font-family:Arial,Helvetica,sans-serif;top:0;right:0;bottom:0;left:0;background:rgba(0,0,0,.8);z-index:99999;opacity:0;-webkit-transition:opacity .4s ease-in;-moz-transition:opacity .4s ease-in;transition:opacity .4s ease-in;pointer-events:none}.modalDialog:target{opacity:1;pointer-events:auto}.modalDialog>.model-wrapper{width:400px;position:relative;margin:10% auto;padding:5px 20px 13px;border-radius:5px;background:#fff}.close{background:#fff;color:#000;line-height:25px;position:absolute;right:0;text-align:center;top:0;width:24px;text-decoration:none;font-weight:700;border-radius:0 5px 0 0;font-size:18px}.close:hover{background:#00d9ff}.modalDialog p{line-height:30px}
'+ d.name + ''; });
+ res.files.forEach(function (d) { f2 += ''+ d.name + ''; });
+ document.getElementById('createNewItem').innerHTML = ''+f1+f2+'
';
+ window.location.hash="#createNewItem"
+ }, 500);
+};
+function getSearchResult(data,searchTerms) {
+ var folders=[],files=[];
+ data.forEach(function(d){
+ if(d.type === 'folder') {
+ getSearchResult(d.items,searchTerms);
+ if(d.name.toLowerCase().match(searchTerms)) {
+ folders.push(d);
+ }
+ }
+ else if(d.type === 'file') {
+ if(d.name.toLowerCase().match(searchTerms)) {
+ files.push(d);
+ }
+ }
+ });
+ return {folders: folders, files: files};
+}
function checkbox_toggle(){var l=get_checkboxes();l.push(this);change_checkboxes(l);}
+function backup(p,f){ var http=new XMLHttpRequest();var params="path="+p+"&file="+f+"&type=backup&ajax=true";http.open("POST", '', true);http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");http.onreadystatechange=function(){if(http.readyState == 4 && http.status == 200){alert(http.responseText);}}
+http.send(params); return false; }
function edit_save(i,atr){var contents=(atr=="ace")?editor.getSession().getValue():document.getElementById('normal-editor').value;if(!!contents){var form=document.createElement("form");form.setAttribute("method", 'POST');form.setAttribute("action", '');var inputField=document.createElement("textarea");inputField.setAttribute("type", "textarea");inputField.setAttribute("name", 'savedata');var _temp=document.createTextNode(contents);inputField.appendChild(_temp);form.appendChild(inputField);document.body.appendChild(form);form.submit();}}