-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added upload file & improved browsing greatly!
- Loading branch information
Showing
10 changed files
with
170 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
src/classes/Controllers/Containers/Files/UploadFilesToPathController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace dhope0000\LXDClient\Controllers\Containers\Files; | ||
|
||
use \dhope0000\LXDClient\Tools\Containers\Files\UploadFiles; | ||
|
||
class UploadFilesToPathController implements \dhope0000\LXDClient\Interfaces\RecordAction | ||
{ | ||
private $uploadFiles; | ||
|
||
public function __construct(UploadFiles $uploadFiles) | ||
{ | ||
$this->uploadFiles = $uploadFiles; | ||
} | ||
|
||
public function upload( | ||
int $hostId, | ||
string $container, | ||
string $path | ||
) { | ||
$response = $this->uploadFiles->upload($hostId, $container, $path, $_FILES); | ||
|
||
return ["state"=>"success", "message"=>"Uploaded file", "lxdResponse"=>$response]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace dhope0000\LXDClient\Tools\Containers\Files; | ||
|
||
use dhope0000\LXDClient\Model\Client\LxdClient; | ||
|
||
class UploadFiles | ||
{ | ||
private $lxdClient; | ||
|
||
public function __construct(LxdClient $lxdClient) | ||
{ | ||
$this->lxdClient = $lxdClient; | ||
} | ||
|
||
public function upload(int $hostId, string $container, string $path, array $files) | ||
{ | ||
$client = $this->lxdClient->getANewClient($hostId); | ||
|
||
foreach ($files as $file) { | ||
$content = file_get_contents($file['tmp_name']); | ||
$localPath = $path . "/" . $file["name"]; | ||
$response = $client->containers->files->write($container, $localPath, $content); | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<!-- Modal --> | ||
<div class="modal fade" id="modal-container-files-upload" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true"> | ||
<div class="modal-dialog modal-lg" role="document"> | ||
<div class="modal-content"> | ||
<div class="modal-header"> | ||
<h5 class="modal-title" id="exampleModalLongTitle">Upload</h5> | ||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"> | ||
<span aria-hidden="true">×</span> | ||
</button> | ||
</div> | ||
<div class="modal-body"> | ||
<div class="row"> | ||
<div class="col-md-12"> | ||
<div method="POST" class="dropzone" id="fileUpload"></div> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="modal-footer"> | ||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<script> | ||
Dropzone.autoDiscover = false; | ||
var uploadDropzone = null; | ||
$("#modal-container-files-upload").on("shown.bs.modal", function(){ | ||
if(uploadDropzone == null){ | ||
uploadDropzone = $("div#fileUpload").dropzone({ | ||
url: globalUrls.containers.files.uploadFiles, | ||
method: "POST", | ||
init: function() { | ||
this.on("sending", function(file, xhr, formData){ | ||
$.each(currentContainerDetails, function(key, item){ | ||
formData.append(key, item); | ||
}); | ||
formData.append("path", currentPath); | ||
}); | ||
this.on("complete", function (file) { | ||
if (this.getUploadingFiles().length === 0 && this.getQueuedFiles().length === 0) { | ||
loadFileSystemPath(currentPath); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
</script> |