-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
125 lines (112 loc) · 4.36 KB
/
index.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
require "config.php";
if(isset($_REQUEST['path'])){
$path = '/'.$_REQUEST['path'].'/';
}else{
$path = PATH;
}
$conn_id = ftp_connect(FTP_SERVER); // set up basic connection
$login_result = ftp_login($conn_id, FTP_USERNAME, FTP_PASSWORD) or die("<h2 class='error'>Permission refusé pour se connecter</h2>"); // login with username and password, or give invalid user message
ftp_pasv($conn_id, true) or die("Cannot switch to passive mode");
if ((!$conn_id) || (!$login_result)) { // check connection
// wont ever hit this, b/c of the die call on ftp_login
echo "La connexion FTP a échoué! <br />";
exit;
}
if(isset($_POST['SubmitFile'])){
$myFile = $_FILES['txt_file']; // This will make an array out of the file information that was stored.
$file = $myFile['tmp_name']; //Converts the array into a new string containing the path name on the server where your file is.
$myFileName = basename($_POST['txt_fileName']); //Retrieve filename out of file path
$destination_file = $path.$myFileName; //where you want to throw the file on the webserver (relative to your login dir)
$upload = ftp_put($conn_id, $destination_file, $file, FTP_BINARY); // upload the file
if (!$upload) { // check upload status
echo "<h2 class='error'>Envois $myFileName a échoué !</h2> <br />";
} else {
echo "<h2 class='success'>Envois $myFileName a réussi !</h2><br /><br />";
}
}
$tree = "";
$explode_path = explode("/",$path);
$explode_path[0] = "/";
// Remove empty
$explode_path = array_filter($explode_path, function($value) { return $value !== ''; });
for($i=0; $i < count($explode_path); $i++){
$explode_path_temp = $explode_path;
for($j=$i; $j < count($explode_path)-1; $j++){
array_pop($explode_path_temp);
}
$folder_path = implode("/",$explode_path_temp);
$tree .="<li>".$folder_path."<ul>";
}
$folders = "";
$files = "";
$listFolderFile = ftp_nlist($conn_id,$path);
asort($listFolderFile);
foreach($listFolderFile as $file){
$explode_file = explode("/",$file);
if(ftp_size($conn_id, $file) !== -1){
$files .= "<li>".array_pop($explode_file)."</li>";
}else{
$folders .= "<li>".$file."<ul></ul></li>";
}
}
$tree .= $folders.$files;
foreach($explode_path as $folder){
$tree .="</ul></li>";
}
ftp_close($conn_id); // close the FTP stream
?>
<html>
<head>
<link href="main.css" rel="stylesheet">
</head>
<body>
<div class="folder-tree">
<div class="box">
<h2>Explorateur de dossier</h2>
<ul class="directory-list">
<?php echo $tree; ?>
</ul>
</div>
</div>
<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
<div class="frame">
<div class="information">
<h2>Dossier cible :</h2>
<h3><?php echo $path ?></h3>
</div>
<div class="center">
<div class="bar"></div>
<div class="title">Déposer un fichier</div>
<div class="dropzone">
<div class="content">
<img src="assets/upload.png" class="upload">
<span class="filename"></span>
<input class="input" name="txt_file" type="file" id="txt_file" tabindex="1" size="35" onChange="txt_fileName.value=txt_file.value" />
</div>
</div>
<img src="assets/syncing.png" class="syncing">
<img src="assets/checkmark.png" class="done">
<input name="txt_fileName" type="hidden" id="txt_fileName" tabindex="99" size="1" />
<input name="path" type="hidden" value="<?php echo $path; ?>"/>
<input class="upload-btn" type="submit" name="SubmitFile" value="Valider" accesskey="ENTER" tabindex="2" />
</div>
<div class="warning">
<h3>Si le fichier existe déjà il sera remplacer</h3>
</div>
</div>
</form>
<div class="shortcut">
<h2>Raccourcis</h2>
<ul id="nav">
<li>
<a href="?path=/exemple/">
Exemple
</a>
</li>
</ul>
</div>
</body>
<script src="vendor/jquery-3.3.1.min.js"></script>
<script src="main.js"></script>
<html>