-
Notifications
You must be signed in to change notification settings - Fork 0
/
dir-js.php
99 lines (89 loc) · 2.58 KB
/
dir-js.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/**
*@author: Heiter Developer <[email protected]>
*@link: https://github.com/HeiterDeveloper/dir-js
*@copyright: 2020 Heiter Developer
*@license: Apache License 2.0
*@license: https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
**/
require("SimpleThumbPHP.class.php");
define("DIRROOT", "/var/www/teste");
define("DIRFILES", DIRROOT."/uploads/");
define("DIRCACHE", "cache/");
define("OUTDIRFILES", str_replace(DIRROOT, "", DIRFILES));
$p = $_POST['target'];
$p2 = $_POST['command'];
$p3 = $_POST['namedir'];
$p4 = $_FILES['arquivo'];
function thumbArquivo($file){
$typeFile = mime_content_type($file);
if(preg_match("/image/", $typeFile)){
$ext = pathinfo($file)['extension'];
$nm = sha1($file);
$thumbDefault = DIRROOT."/".DIRCACHE.$nm.".$ext";
if(!file_exists($thumbDefault)){
$mode = 'C';
$modeFile = 'S';
$myImg = new SimpleThumbPHP();
$myImg->create($file, 150, 150, $mode);
$myImg->save($modeFile, $thumbDefault);
}
}
return str_replace(DIRROOT."/", "", $thumbDefault);
}
function listDir($dir){
$outCommand = array();
$itens = array();
$fullName = (DIRFILES == $dir . "/") ? "" : str_replace(DIRFILES, "", $dir);
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$thumbFile = thumbArquivo("$dir/$file");
$isDir = (is_dir("$dir/$file")) ? "T" : "F";
$itens[] = array("nome"=>$file, "dir"=>$isDir, "thumbFile"=>$thumbFile);
}
}
$outCommand = array("dir"=>$fullName, "dirFiles"=>OUTDIRFILES, "itens"=>$itens);
echo json_encode($outCommand);
closedir($handle);
}
else{
$outCommand = array("dir"=>$fullName, "dirFiles"=>OUTDIRFILES, "vazio"=>1);
echo json_encode($outCommand);
}
}
header("Content-type: application/json");
if($p == "default"){
listDir(DIRFILES);
}
if($p2 == "cd"){
listDir(DIRFILES."$p");
}
if($p2 == "newDir"){
mkdir(DIRFILES."$p/$p3");
listDir(DIRFILES."$p");
}
if($p2 == "renameDir"){
$oldNameFile = DIRFILES."$p/".$p3['oldName'];
$ext = (!is_dir($oldNameFile)) ? ".".pathinfo($oldNameFile)['extension'] : '';
rename($oldNameFile, DIRFILES.$p."/".$p3['newName'].$ext);
listDir(DIRFILES."$p");
}
if($p2 == "back"){
$cm = dirname(DIRFILES . $p, 1);
if($p == ""){
$cm = DIRFILES;
}
listDir($cm);
}
if($p2 == "delDir"){
foreach($p3 as $pos){
exec("rm -fr \"". DIRFILES.$p."/$pos\"");
}
listDir(DIRFILES."$p");
}
if($p2 == "upload"){
move_uploaded_file($p4['tmp_name'], DIRFILES."$p/".$p4['name']);
listDir(DIRFILES."$p");
}
?>