Skip to content

Commit 9626c44

Browse files
committed
php demo handler now allows file uploads
1 parent ae14e80 commit 9626c44

File tree

5 files changed

+44
-8
lines changed

5 files changed

+44
-8
lines changed

bridges/php/handler.php

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,21 @@ abstract class Request
3333
public static function getQuery($param = null, $default = null)
3434
{
3535
if ($param) {
36-
return isset($_GET[$param]) ? $_GET[$param] : $default;
36+
return isset($_GET[$param]) ?
37+
$_GET[$param] : $default;
3738
}
3839
return $_GET;
3940
}
4041

42+
public static function getPost($param = null, $default = null)
43+
{
44+
if ($param) {
45+
return isset($_POST[$param]) ?
46+
$_POST[$param] : $default;
47+
}
48+
return $_POST;
49+
}
50+
4151
public static function getPostContent()
4252
{
4353
$rawData = file_get_contents('php://input');
@@ -127,6 +137,25 @@ public function getContent($path)
127137
$oFtp->connect();
128138
$oResponse = new Response();
129139

140+
if ($_FILES) {
141+
$dest = Request::getPost('destination');
142+
$errors = array();
143+
foreach ($_FILES as $file) {
144+
$filePath = $file['tmp_name'];
145+
$destPath = $dest .'/'. $file['name'];
146+
$result = $oFtp->upload($filePath, $destPath);
147+
if (! $result) {
148+
$errors[] = $file['name'];
149+
}
150+
}
151+
if ($errors) {
152+
throw new Exception("Unknown error uploading: " . "\n" . implode($errors, ", \n"));
153+
}
154+
155+
$oResponse->setData($result);
156+
$oResponse->flushJson();
157+
}
158+
130159
if (Request::getApiParam('mode') === 'list') {
131160
$list = $oFtp->listFilesRaw(Request::getApiParam('path'));
132161
$list = is_array($list) ? $list : array();
@@ -155,6 +184,11 @@ public function getContent($path)
155184
$oResponse->flushJson();
156185
}
157186

187+
if (Request::getApiParam('mode') === 'compress' || Request::getApiParam('mode') === 'extract') {
188+
$oResponse->setData(true);
189+
$oResponse->flushJson();
190+
}
191+
158192
if (Request::getQuery('mode') === 'download') {
159193
$download = Request::getQuery('preview') === 'true' ? '' : 'attachment;';
160194
$filePath = Request::getQuery('path');
@@ -171,4 +205,4 @@ public function getContent($path)
171205
$oResponse->flush();
172206
}
173207

174-
throw new \Exception('This action is not available in the demo');
208+
throw new \Exception('This action is not available in the demo');

dist/angular-filemanager.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/angular-filemanager.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/css/angular-filemanager.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ textarea.code {
7171
text-align: left;
7272
}
7373

74+
.modal .label.error-msg > span {
75+
white-space: pre-wrap;
76+
}
77+
7478
.bold {
7579
font-weight: bold;
7680
}

src/templates/modals.html

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,6 @@ <h4 class="modal-title">{{'change_permissions' | translate}}</h4>
305305
<h4 class="modal-title">{{"select_destination_folder" | translate}}</h4>
306306
</div>
307307
<div class="modal-body">
308-
309-
310-
311308
<div>
312309
<div ng-include="config.tplPath + '/current-folder-breadcrumb.html'"></div>
313310
<div ng-include="config.tplPath + '/main-table-modal.html'"></div>
@@ -335,6 +332,7 @@ <h4 class="modal-title">{{"select_destination_folder" | translate}}</h4>
335332
</script>
336333
<script type="text/ng-template" id="error-bar">
337334
<div class="label label-danger error-msg pull-left animated fadeIn" ng-show="temp.error">
338-
<i class="glyphicon glyphicon-remove-circle"></i> {{temp.error}}
335+
<i class="glyphicon glyphicon-remove-circle"></i>
336+
<span>{{temp.error}}</span>
339337
</div>
340338
</script>

0 commit comments

Comments
 (0)