-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
63 lines (53 loc) · 1.5 KB
/
index.php
File metadata and controls
63 lines (53 loc) · 1.5 KB
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
<?php
/**
* @file index - router file for handling all requests
* @recieves the following request params -
* ==> res : index,view or download
* ==> path:storage path name of resource
*/
require_once '__backend/Storage.php';
$host="http://localhost:8082/smartdrive/"; // IP and port where app is hosted
$res=(isset($_GET['res'])) ? $_GET['res'] : 'index';
$path=(isset($_GET['path'])) ? $_GET['path'] : null;
/**
* check if the user is accessing the root of the app
*/
if($res=='index'){
$dir='Storage';
$dirSize=ceil(Storage::getSize($dir)/1000000);
$dirDisp=ucfirst('root');
$contents=Storage::getDirInfo('storage');
return require_once 'views/index.php';
}
/**
* Check if user wants to see the log
*/
if($res=='log'){
$logs=Storage::prepLog()->files;
return require_once 'views/log.php';
}
/* validate request */
if(!$path || !$res){
$msg="Unknown Request Path or Resource was not defined!";
return require_once 'views/status.php';
}
if(file_exists($path)){
if($res=='view'){
$dirSize=ceil(Storage::getSize($path)/1000000);
$contents=Storage::getDirInfo($path);
$dirs=explode('/',$path);
$dirDisp=ucfirst($dirs[count($dirs)-1]);
return require_once 'views/view.php';
}
elseif($res='download'){
return Storage::download($path);
}
else{
$msg="Unknown Request Path or Resource was not defined!";
return require_once 'view/status.php';
}
}
else{
require_once 'views/404.php';
}
?>