summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEole <EoleDev@outlook.fr>2016-05-09 22:39:49 +0200
committerEole <EoleDev@outlook.fr>2016-05-09 22:39:49 +0200
commit77ba8021bc4d910afd4d4c9d0a9fe9077c9a00ea (patch)
tree3f2fe6162fe4059d204d886ff1ef650bd933d283
parenta7d79d60abd26cf2b9ceaa1c7f657d8a34677f9c (diff)
File Upload AJAX
-rwxr-xr-xclient/index.html4
-rwxr-xr-x[-rw-r--r--]client/js/controllers/image/edit.js13
-rwxr-xr-xclient/partials/image/edit.html8
-rwxr-xr-xserver/core/Image.php21
4 files changed, 36 insertions, 10 deletions
diff --git a/client/index.html b/client/index.html
index 3dd501a..ad51d8d 100755
--- a/client/index.html
+++ b/client/index.html
@@ -10,6 +10,7 @@
<link rel="stylesheet" href="./vendors/bootstrap/css/bootstrap.css">
<link rel="stylesheet" href="./css/style.css">
<link rel="stylesheet" href="./vendors/jointjs/css/joint.min.css">
+ <link rel="stylesheet" href="./vendors/jquery-File-Upload/jquery.fileupload.css">
<link rel="stylesheet" href="./css/graph.css">
@@ -70,6 +71,9 @@
<!-- Include JQuery -->
<script src="./vendors/jquery/jquery-2.2.0.min.js"></script>
+ <script src="./vendors/jquery-File-Upload/jquery.ui.widget.js"></script>
+ <script src="./vendors/jquery-File-Upload/jquery.iframe-transport.js"></script>
+ <script src="./vendors/jquery-File-Upload/jquery.fileupload.js"></script>
<script src="./vendors/jquery/dmuploader.min.js"></script>
<!-- Include Bootstrap -->
diff --git a/client/js/controllers/image/edit.js b/client/js/controllers/image/edit.js
index 776f88f..e1da271 100644..100755
--- a/client/js/controllers/image/edit.js
+++ b/client/js/controllers/image/edit.js
@@ -20,6 +20,17 @@ mainApp.controller('editImageCtrl', ['$scope', 'Image', 'Loading', 'Identity', '
$scope.axioms = axioms;
$('#editImageModal').modal('show');
+ $("#fileupload").fileupload({
+ formData: {task: "image", token: Identity.getToken(), action: "uploadImage", id: $scope.data.id},
+ /* ... */
+ progressall: function (e, data) {
+ var progress = parseInt(data.loaded / data.total * 100, 10);
+ $('#progress .bar').css(
+ 'width',
+ progress + '%'
+ );
+ }
+ });
});
$scope.applyEdition = function (id) {
@@ -34,4 +45,6 @@ mainApp.controller('editImageCtrl', ['$scope', 'Image', 'Loading', 'Identity', '
$scope.getToken = function () {
return Identity.getToken();
}
+
+
}]);
diff --git a/client/partials/image/edit.html b/client/partials/image/edit.html
index 3b37c3b..d5c3621 100755
--- a/client/partials/image/edit.html
+++ b/client/partials/image/edit.html
@@ -34,7 +34,11 @@
</fieldset>
</form>
- <form action="../server/index.php" enctype="multipart/form-data" method="post" ng-if='image.status == "queued"'>
+ <input id="fileupload" type="file" name="files" data-url="../server/index.php">
+ <div id="progress">
+ <div class="bar" style="width: 0%;"></div>
+ </div>
+ <!-- <form action="../server/index.php" enctype="multipart/form-data" method="post" ng-if='image.status == "queued"'>
<input type="hidden" name="task" value="image" />
<input type="hidden" name="token" value="{{ getToken()}}" />
<input type="hidden" name="action" value="uploadImage" />
@@ -48,7 +52,7 @@
<input type="submit" value="Upload"/>
</fieldset>
- </form>
+ </form> -->
<div class="modal-footer">
<!--<a href="#" data-dismiss="modal" class="btn btn-default">Close</a>-->
diff --git a/server/core/Image.php b/server/core/Image.php
index f8cac04..41eb9d8 100755
--- a/server/core/Image.php
+++ b/server/core/Image.php
@@ -377,7 +377,7 @@ class image implements Core{
}
}
}
-
+
/**
* Upload an image
*
@@ -388,9 +388,9 @@ class image implements Core{
*/
private function uploadImage(){
$id = $this->app->getPostParam("id");
- $file_name = $_FILES['file']['name'];
- $file_error = $_FILES['file']['error'];
- $file_tmp = $_FILES['file']['tmp_name'];
+ $file_name = $_FILES['files']['name'];
+ $file_error = $_FILES['files']['error'];
+ $file_tmp = $_FILES['files']['tmp_name'];
switch($file_error){
case UPLOAD_ERR_INI_SIZE:
@@ -405,10 +405,15 @@ class image implements Core{
return;
}
if( !is_uploaded_file($file_tmp) )
- {
- $this->app->setOutput("Error", "File Upload Error");
- return;
- }
+ {
+ //$this->app->setOutput("Error", "File Upload Error");
+ file_put_contents(
+ $file_tmp,
+ fopen("php://input", 'r'),
+ FILE_APPEND
+ );
+
+ }
if(!isset($id)){
$this->app->setOutput("Error", "Incorrect id parameter");