Skip to content

Commit 1a49a88

Browse files
committed
1.0.0
1 parent a2fb817 commit 1a49a88

File tree

8 files changed

+473
-0
lines changed

8 files changed

+473
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
configuration.php
2+
dir/
3+
temp/

css/index.css

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
body{
2+
margin: 1%;
3+
}
4+
.tdBtn{
5+
text-align: center;
6+
}
7+
.tdHr{
8+
margin: 0px;
9+
}
10+
.aBack{
11+
text-decoration: none;
12+
}
13+
.tdName{
14+
max-width: 50vw;
15+
overflow: hidden;
16+
display: inline-block;
17+
text-overflow: ellipsis;
18+
cursor: pointer;
19+
margin: 0.2em;
20+
margin-right: 1em;
21+
}
22+
.menuBtn{
23+
margin: 0.33em;
24+
margin: 0.5em;
25+
font-weight: bold;
26+
}
27+
input[type=button]{
28+
cursor: pointer;
29+
}
30+
input{
31+
font-size: 1em;
32+
}
33+
.editorInp{
34+
margin: 1%;
35+
margin-top: 2%;
36+
margin-bottom: 0px;
37+
margin-right: 0px;
38+
}
39+
body{
40+
font-family: sans-serif;
41+
}
42+
.loginInput{
43+
width: 10em;
44+
margin: 0.2em;
45+
}

index.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
session_start();
3+
include('./lib/initialization.php');
4+
Initialization::_main();
5+
include('./configuration.php');
6+
?>
7+
<head>
8+
<title id="title"><?php $configuration["title"];?></title>
9+
<link rel="stylesheet" href="./css/index.css" type="text/css"/>
10+
<script src="./js/index.js"></script>
11+
</head>
12+
<body>
13+
<?php
14+
include('./lib/handlerDirectory.php');
15+
include('./lib/userInterface.php');
16+
include('./lib/handlerFile.php');
17+
18+
$handlerDirectory = new HandlerDirectory();
19+
$userInterface = new UserInterface();
20+
$handlerFile = new HandlerFile();
21+
22+
if(isset($_POST["userName"]))
23+
if($_POST["userName"]==$configuration["login"])
24+
if($_POST["password"]==$configuration["pwd"])
25+
$_SESSION["user"]=true;
26+
27+
if(isset($_SESSION["user"])){
28+
if(isset($_GET['dwld']))
29+
$handlerFile->downloadFile(".".$_GET['dwld']);
30+
31+
if(isset($_GET['cDir']))
32+
$handlerDirectory->createDirectory($_GET['link'], $_GET['cDir']);
33+
34+
if(isset($_GET['cFile']))
35+
$handlerFile->createFile($_GET['link'], $_GET['cFile']);
36+
37+
if(isset($_GET['dFileName']))
38+
$handlerFile->deleteFile($_GET['link'], $_GET['dFileName']);
39+
40+
if(isset($_GET['dDirName']))
41+
$handlerDirectory->deleteDirectory($_GET['link'], $_GET['dDirName']);
42+
43+
if(isset($_GET['dwldDirName']))
44+
$handlerFile->directoryToZip($_GET['link'], $_GET['dwldDirName']);
45+
46+
if(isset($_POST['sFile']))
47+
$handlerFile->saveFile($_POST['link'], $_POST['sFile'], $_POST['text']);
48+
49+
if(isset($_FILES['uploadFile']))
50+
$handlerFile->uploadFile($_FILES, $_GET["uploadFile"]);
51+
52+
if(!isset($_GET["link"]))
53+
$_GET["link"]="";
54+
55+
echo $userInterface->editor();
56+
echo $userInterface->explorer($_GET["link"]);
57+
echo $userInterface->uploadFile($_GET["link"]);
58+
}else{
59+
echo $userInterface->login();
60+
}
61+
62+
?>
63+
</body>

js/index.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
function createDirectory(link){
2+
let dname = prompt('Enter the name of the directory (only ASCII):');
3+
if(dname!=null)
4+
location.href = '?link='+encodeURIComponent(link)+
5+
'&cDir='+encodeURIComponent(dname);
6+
}
7+
8+
function createFile(link){
9+
let dname = prompt('Enter the name of the file (only ASCII):');
10+
if(dname!=null)
11+
location.href = '?link='+encodeURIComponent(link)+
12+
'&cFile='+encodeURIComponent(dname);
13+
}
14+
15+
function deleteFile(link, fileName){
16+
if(confirm('Do you really want to delete the '+fileName+' file?'))
17+
location.href = '?link='+encodeURIComponent(link)+
18+
'&dFileName='+encodeURIComponent(fileName);
19+
}
20+
21+
function deleteDirectory(link, dirName){
22+
if(confirm('Do you really want to delete the '+dirName+' directory?'))
23+
location.href = '?link='+encodeURIComponent(link)+
24+
'&dDirName='+encodeURIComponent(dirName);
25+
}
26+
27+
function dwldDirectory(link, dirName){
28+
location.href = '?link='+encodeURIComponent(link)+
29+
'&dwldDirName='+encodeURIComponent(dirName);
30+
}
31+
32+
function getFileText(link){
33+
var xhr = new XMLHttpRequest();
34+
xhr.open('GET', link, false);
35+
xhr.send();
36+
if (xhr.status != 200) {
37+
alert(xhr.status+': '+xhr.statusText);
38+
} else {
39+
document.getElementById('taEditor').innerHTML = xhr.responseText;
40+
}
41+
}
42+
43+
function closeEditor(){
44+
document.getElementById('taEditor').innerHTML = '';
45+
document.getElementById('inpEditor').value = '';
46+
document.getElementById('divEditor').style.display = 'none';
47+
document.getElementById('saveEditorBtn').onclick = function() {};
48+
}
49+
50+
function editFile(link, fileName){
51+
closeEditor();
52+
getFileText('?dwld=/dir'+link+'/'+fileName);
53+
document.getElementById('inpEditor').value = fileName;
54+
document.getElementById('divEditor').style.display = 'block';
55+
document.getElementById('saveEditorBtn').onclick = function() { saveFile(link, fileName); };
56+
}
57+
58+
function saveFile(link, fileName){
59+
var xhr = new XMLHttpRequest();
60+
xhr.open('POST', '/', true);
61+
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
62+
xhr.send(
63+
'link='+encodeURIComponent(link)+
64+
'&sFile='+encodeURIComponent(fileName)+
65+
'&text='+encodeURIComponent(document.getElementById('taEditor').value)
66+
);
67+
}
68+
69+
function uploadFile(link){
70+
document.getElementById('uploadFile').style.display = 'block';
71+
}
72+
73+
function closeUploader(link){
74+
document.getElementById('uploadFile').style.display = 'none';
75+
}

lib/handlerDirectory.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
class HandlerDirectory {
3+
private function rmDirectory($dir) {
4+
if (is_dir($dir)) {
5+
$objects = scandir($dir);
6+
foreach ($objects as $object) {
7+
if ($object != "." && $object != "..") {
8+
if (is_dir($dir. DIRECTORY_SEPARATOR .$object) && !is_link($dir."/".$object))
9+
$this->rmDirectory($dir. DIRECTORY_SEPARATOR .$object);
10+
else
11+
unlink($dir. DIRECTORY_SEPARATOR .$object);
12+
}
13+
}
14+
rmdir($dir);
15+
}
16+
}
17+
18+
function deleteDirectory($link, $dirName){
19+
$this->rmDirectory("./dir".$link."/".$dirName);
20+
header("Location: ?link=".urlencode($link));
21+
}
22+
23+
function createDirectory($link, $dirName){
24+
$dirName = preg_replace('/[^\x20-\x7E]/','', $dirName);
25+
mkdir("./dir".$link."/".$dirName, 0755);
26+
header("Location: ?link=".urlencode($link));
27+
}
28+
}
29+
?>

lib/handlerFile.php

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
class HandlerFile {
3+
function downloadFile($file, $customName="") {
4+
if (file_exists($file)) {
5+
if (ob_get_level())
6+
ob_end_clean();
7+
if($customName=="")
8+
$customName = basename($file);
9+
header('Content-Description: File Transfer');
10+
header('Content-Type: application/octet-stream');
11+
header('Content-Disposition: attachment; filename='.$customName);
12+
header('Content-Transfer-Encoding: binary');
13+
header('Expires: 0');
14+
header('Cache-Control: must-revalidate');
15+
header('Pragma: public');
16+
header('Content-Length: ' . filesize($file));
17+
if ($fd = fopen($file, 'rb')) {
18+
while (!feof($fd)) {
19+
print fread($fd, 1024);
20+
}
21+
fclose($fd);
22+
}
23+
exit;
24+
}
25+
}
26+
27+
function uploadFile($files, $link){
28+
$totalFiles = count($_FILES['uploadFile']['name']);
29+
for($key = 0; $key < $totalFiles; $key++)
30+
move_uploaded_file($files['uploadFile']['tmp_name'][$key], "./dir".$link."/".basename($files['uploadFile']['name'][$key]));
31+
32+
header("Location: ?link=".urlencode($link));
33+
}
34+
35+
function addFileRecursion($zip, $dir, $start = ''){
36+
if (empty($start)) {
37+
$start = $dir;
38+
}
39+
if ($objs = glob($dir . '/*')) {
40+
foreach($objs as $obj) {
41+
if (is_dir($obj)) {
42+
$this->addFileRecursion($zip, $obj, $start);
43+
} else {
44+
$zip->addFile($obj, str_replace(dirname($start) . '/', '', $obj));
45+
}
46+
}
47+
}
48+
}
49+
50+
function createFile($link, $fileName){
51+
$fileName = preg_replace('/[^\x20-\x7E]/','', $fileName);
52+
file_put_contents("./dir".$link."/".$fileName, "");
53+
header("Location: ?link=".urlencode($link));
54+
}
55+
56+
function deleteFile($link, $fileName){
57+
unlink("./dir".$link."/".$fileName);
58+
header("Location: ?link=".urlencode($link));
59+
}
60+
61+
62+
function saveFile($link, $fileName, $text){
63+
file_put_contents("./dir".$link."/".$fileName, $text);
64+
header("Location: ?link=".urlencode($link));
65+
}
66+
67+
function directoryToZip($link, $dirName){
68+
$zip = new ZipArchive();
69+
$aLink="./temp/".$dirName.".zip";
70+
$zip->open($aLink, ZipArchive::CREATE|ZipArchive::OVERWRITE);
71+
$this->addFileRecursion($zip, "./dir".$link."/".$dirName);
72+
$zip->close();
73+
$this->downloadFile($aLink, $dirName."_".date("Y_m_d_H_i_s").".zip");
74+
header("Location: ?link=".urlencode($link));
75+
}
76+
}
77+
?>

lib/initialization.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
class Initialization {
3+
static function _main(){
4+
if(!is_dir("./temp"))
5+
mkdir("./temp", 0755, true);
6+
7+
if(!is_dir("./dir"))
8+
mkdir("./dir", 0755, true);
9+
10+
if (!file_exists("./configuration.php"))
11+
file_put_contents("./configuration.php", "
12+
<?php
13+
\$configuration=[
14+
\"login\" => \"admin\",
15+
\"pwd\" => \"admin\",
16+
\"title\" => \"php-explorer-simple\"
17+
];
18+
?>
19+
");
20+
}
21+
}

0 commit comments

Comments
 (0)