forked from TobiHatti/DA-WebSite-BadmintonOOE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfroalapl-upload-file.php
157 lines (130 loc) · 5.99 KB
/
froalapl-upload-file.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
session_start();
require("headerlinks.php");
require("headerincludes.php");
if(isset($_POST['uploadFroalaFile']))
{
$id = uniqid();
$displayName = $_POST['display'];
/*
$filename = SReplace($_FILES['file']['name'][0]);
$extension = pathinfo($filename, PATHINFO_EXTENSION);
// Adding a "-u" in the end of the filename avoids first duplicate override
$filenameNoExtension = str_replace('.'.$extension,'',$filename).'-u';
$filename = $filenameNoExtension.'.'.$extension;
// In case the ID already exists, cycle
if(MySQL::Exist("SELECT filename FROM uploads WHERE filename = ?",'@s',$filename))
{
$i=2;
do
{
$newFilename = $filenameNoExtension.'-'.$i;
$newFilenamePlusExtension = $newFilename.'.'.$extension;
$i++;
}
while(MySQL::Exist("SELECT filename FROM uploads WHERE filename = ?",'@s',$newFilenamePlusExtension));
$filename = $newFilename.'.'.$extension;
$filenameNoExtension = $newFilename;
}
if($displayName == '') $displayName = $filename;
FileUpload("files/pagecontent/","file","","","INSERT INTO uploads (id,filename,displayname) VALUES ('$id','$filename','$displayName')",$filenameNoExtension);
*/
// Creating the uploader
$uploader = new FileUploader();
// Setting the general upload-settings
$uploader->SetFileElement("file");
$uploader->SetPath("files/pagecontent/");
$uploader->OverrideDuplicates(false);
// Setting the SQL-Entry
$uploader->SetSQLEntry("INSERT INTO uploads (id,filename,displayname) VALUES ('$id','@FUO_FILENAMEPLUSEXTENSION','$displayName')");
// Uploading the file to the Server
$uploader->Upload();
Redirect(ThisPage("+uploadComplete=$id"));
die();
}
if(isset($_GET['uploadComplete']))
{
$uploadData = MySQL::Row("SELECT * FROM uploads WHERE id = ?",'s',$_GET['uploadComplete']);
echo '
<h4>Datei wurde hochgeladen!</h4>
<center>
<img src="/content/success.gif" alt="" style="width: 200px;"/>
<br>
<i><span style="color: #696969; font-size: 10pt;">'.$uploadData['displayname'].' ['.$uploadData['filename'].']</span></i>
<br>
<input type="hidden" id="htmlInsert" value="<a href=\'/files/pagecontent/'.$uploadData['filename'].'\'>'.$uploadData['displayname'].'</a>"/>
<a href="#"><button type="button" onclick="AddStringToFroala(document.getElementById(\'htmlInsert\').value); window.location.replace(\'froalapl-upload-file?parent='.urldecode($_GET['parent']).'\'); window.top.location = \'/'.urldecode($_GET['parent']).'#\'"><i class="fas fa-paste"></i> In Textfeld einfügen</button></a>
</center>
';
}
else if(isset($_GET['existingFiles']))
{
echo '
<h4>Hochgeladene Dateien</h4>
<ul>
';
$strSQL = "SELECT * FROM uploads ORDER BY displayname ASC";
$rs=mysqli_query($link,$strSQL);
while($row=mysqli_fetch_assoc($rs))
{
echo '
<a href="'.ThisPage("-existingFiles","+uploadSelection=".$row['id']).'">
<table style="margin-bottom: 5px;" class="hoverFocus">
<tr>
<td rowspan=2>
<li></li>
</td>
<td>
<span style="font-size: 12pt;">'.$row['displayname'].'</span>
</td>
</tr>
<tr>
<td>
<span style="color: #696969; font-size: 10pt;">['.$row['filename'].']</span>
</td>
</tr>
</table>
</a>
';
}
echo '
</ul>
';
}
else if(isset($_GET['uploadSelection']))
{
$uploadData = MySQL::Row("SELECT * FROM uploads WHERE id = ?",'s',$_GET['uploadSelection']);
echo '
<h4>Datei wurde ausgewählt!</h4>
<center>
<img src="/content/success.gif" alt="" style="width: 200px;"/>
<br>
<i><span style="color: #696969; font-size: 10pt;">'.$uploadData['displayname'].' ['.$uploadData['filename'].']</span></i>
<br>
<input type="hidden" id="htmlInsert" value="<a href=\'/files/pagecontent/'.$uploadData['filename'].'\'>'.$uploadData['displayname'].'</a>"/>
<a href="#"><button type="button" onclick="AddStringToFroala(document.getElementById(\'htmlInsert\').value); window.location.replace(\'froalapl-upload-file?parent='.urldecode($_GET['parent']).'\'); window.top.location = \'/'.urldecode($_GET['parent']).'#\'"><i class="fas fa-paste"></i> In Textfeld einfügen</button></a>
</center>
';
}
else
{
echo '
<div class="iframe_content stagfade2" style="font-size: 12pt;">
<h4>Datei hochladen</h4>
<form action="'.ThisPage().'" method="post" accept-charset="utf-8" enctype="multipart/form-data">
<center>
<br>
<input type="text" name="display" class="cel_m" placeholder="Anzeigename (optional)"/><br>
<br>
'.FileButton("file","file",false,"","","width:140px;").'
<br><br>
<button type="submit" name="uploadFroalaFile">Hochladen</button>
<br>
oder<br>
<a href="'.ThisPage("+existingFiles").'">Existierende Datei auswählen</a>
</center>
</form>
</div>
';
}
?>