Pronti a cambiare tutto
This commit is contained in:
parent
8b5886ae69
commit
cbcd729136
5 changed files with 121 additions and 86 deletions
|
@ -2,13 +2,13 @@
|
|||
require_once('request.php');
|
||||
|
||||
class arkiwiRequestGetCreate extends arkiwiRequest {
|
||||
public function run() {
|
||||
if($this->request['method'] != 'GET') {
|
||||
$this->setBodyError(500, "arkiwiRequestGetCreate: GET method required.");
|
||||
return;
|
||||
}
|
||||
public function run() {
|
||||
if($this->request['method'] != 'GET') {
|
||||
$this->setBodyError(500, "arkiwiRequestGetCreate: GET method required.");
|
||||
return;
|
||||
}
|
||||
|
||||
$this->setCode(200);
|
||||
$this->setBodyJSON(Array('id' => $this->createSession()));
|
||||
}
|
||||
$this->setCode(200);
|
||||
$this->setBodyJSON(Array('id' => $this->createSession()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,70 +4,70 @@ require_once('request.php');
|
|||
require_once('../arav_up_inclu/base64codec.php');
|
||||
|
||||
class arkiwiRequestPostUpload extends arkiwiRequest {
|
||||
private $sId = null;
|
||||
private $path = null;
|
||||
private $sId = null;
|
||||
private $path = null;
|
||||
|
||||
public function __construct($request) {
|
||||
parent::__construct($request);
|
||||
|
||||
$extra = $this->getRequestExtra();
|
||||
|
||||
$this->sId = $extra[0];
|
||||
$this->path = "/".decoder($extra[1]);
|
||||
}
|
||||
public function __construct($request) {
|
||||
parent::__construct($request);
|
||||
|
||||
public function run() {
|
||||
report(REPPRIO::DEBUG, "Entering arkiwiRequestPostUpload");
|
||||
|
||||
if($this->request['method'] != 'POST') {
|
||||
report(REPPRIO::FATAL, "arkiwiRequestPostUpload: POST method required.");
|
||||
$this->setBodyError(500, "arkiwiRequestPostUpload: POST method required.");
|
||||
return;
|
||||
}
|
||||
$extra = $this->getRequestExtra();
|
||||
|
||||
if ($this->isSessionValid($this->sId)) {
|
||||
report(REPPRIO::ERROR, "Session invalid or expired.");
|
||||
$this->setBodyError(400, "Session invalid or expired.");
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->path != $_SESSION[authstate]["dir"]) {
|
||||
report(REPPRIO::FATAL, "No permission to write in requested dir :".$this->path);
|
||||
$this->setBodyError(401, "No permission to write in requested dir :".$this->path);
|
||||
return;
|
||||
}
|
||||
$this->sId = $extra[0];
|
||||
$this->path = "/".decoder($extra[1]);
|
||||
}
|
||||
|
||||
$ok = false;
|
||||
public function run() {
|
||||
report(REPPRIO::DEBUG, "Entering arkiwiRequestPostUpload");
|
||||
|
||||
$file = $_FILES[$this->sId];
|
||||
|
||||
if ($file !== FALSE && !empty($file) && $file['error'] == UPLOAD_ERR_OK) {
|
||||
$ok = $this->upload($file, $this->path.'/'.$file['name']);
|
||||
}
|
||||
if($this->request['method'] != 'POST') {
|
||||
report(REPPRIO::FATAL, "arkiwiRequestPostUpload: POST method required.");
|
||||
$this->setBodyError(500, "arkiwiRequestPostUpload: POST method required.");
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->isSessionValid($this->sId)) {
|
||||
report(REPPRIO::ERROR, "Session invalid or expired.");
|
||||
$this->setBodyError(400, "Session invalid or expired.");
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->path != $_SESSION[authstate]["dir"]) {
|
||||
report(REPPRIO::FATAL, "No permission to write in requested dir :".$this->path);
|
||||
$this->setBodyError(401, "No permission to write in requested dir :".$this->path);
|
||||
return;
|
||||
}
|
||||
|
||||
$ok = false;
|
||||
|
||||
$file = $_FILES[$this->sId];
|
||||
|
||||
if ($file !== FALSE && !empty($file) && $file['error'] == UPLOAD_ERR_OK) {
|
||||
$ok = $this->upload($file, $this->path.'/'.$file['name']);
|
||||
}
|
||||
|
||||
if ($ok == false) {
|
||||
report(REPPRIO::ERROR, "Your file has not been upload. Sorry :(");
|
||||
$this->setBodyError(400, "Your file has not been upload. Sorry :(");
|
||||
|
||||
if ($ok == false) {
|
||||
report(REPPRIO::ERROR, "Your file has not been upload. Sorry :(");
|
||||
$this->setBodyError(400, "Your file has not been upload. Sorry :(");
|
||||
|
||||
// $this->closeSession($this->sId);
|
||||
} else {
|
||||
report(REPPRIO::INFO, "Uploaded ".$GLOBALS["conf"]["data_basedir"]." ".$this->path.'/'.$file['name']);
|
||||
$this->setCode(201);
|
||||
$this->setBodyJSON(Array('succeeded' => true));
|
||||
|
||||
} else {
|
||||
report(REPPRIO::INFO, "Uploaded ".$GLOBALS["conf"]["data_basedir"]." ".$this->path.'/'.$file['name']);
|
||||
$this->setCode(201);
|
||||
$this->setBodyJSON(Array('succeeded' => true));
|
||||
|
||||
// $this->closeSession($this->sId);
|
||||
}
|
||||
}
|
||||
|
||||
private function upload($obj, $destinationFolder) {
|
||||
if (!$obj) {
|
||||
|
||||
return false;
|
||||
}
|
||||
report(REPPRIO::DEBUG, "Uploading ".$GLOBALS["conf"]["data_basedir"]." ".$destinationFolder);
|
||||
$realDestination = $GLOBALS["conf"]["data_basedir"].$destinationFolder;
|
||||
$uploadResult = move_uploaded_file($obj['tmp_name'], $realDestination);
|
||||
|
||||
return $uploadResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function upload($obj, $destinationFolder) {
|
||||
if (!$obj) {
|
||||
|
||||
return false;
|
||||
}
|
||||
report(REPPRIO::DEBUG, "Uploading ".$GLOBALS["conf"]["data_basedir"]." ".$destinationFolder);
|
||||
$realDestination = $GLOBALS["conf"]["data_basedir"].$destinationFolder;
|
||||
$uploadResult = move_uploaded_file($obj['tmp_name'], $realDestination);
|
||||
|
||||
return $uploadResult;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,10 +54,18 @@
|
|||
<body>
|
||||
|
||||
<form id="file-form" method="POST">
|
||||
<input type="file" style="visibility: hidden"/>
|
||||
<button type="submit" id="upload-button">Upload</button>
|
||||
<p>Pippone con spiegone, si può anche mettere da un'altra parte, CRI vedi tu quando fai grafica</p>
|
||||
<div>
|
||||
<button type="submit" id="browse-button" onclick="selectFile(event);">Select file to upload</button>
|
||||
</div>
|
||||
<input type="file" id="hiddenfileinput" style="visibility: hidden;"/> <!-- CRI, questo non va toccato, ma può essere spostato -->
|
||||
</form>
|
||||
|
||||
<div id="fileInfo">
|
||||
<article ><span>File: </span><span id="file-name">No file selected</span></article>
|
||||
<button type="submit" id="upload-button" disabled>Upload</button>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$(function() {
|
||||
initialize('<?php echo $GLOBALS["conf"]["api_endpoint"] ?>');
|
||||
|
|
|
@ -55,7 +55,7 @@ ARKIWI.Uploader.prototype.create = function (callbacks) {
|
|||
});
|
||||
};
|
||||
|
||||
/* Invia un file all'asset store. */
|
||||
/* Invia un file all'uploader. */
|
||||
ARKIWI.Uploader.prototype.upload = function (form, destinationFolderBase64, callbacks) {
|
||||
form = $(form);
|
||||
|
||||
|
@ -87,6 +87,28 @@ ARKIWI.Uploader.prototype.upload = function (form, destinationFolderBase64, call
|
|||
form.submit();
|
||||
};
|
||||
|
||||
ARKIWI.Uploader.prototype.upload5 = function (file, destinationFolderBase64, callbacks) {
|
||||
var reader = new FileReader();
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.withCredentials = true;
|
||||
|
||||
var self = this;
|
||||
|
||||
xhr.upload.addEventListener("progress", function(e) {}, false);
|
||||
|
||||
xhr.upload.addEventListener("load", function(e){}, false);
|
||||
|
||||
xhr.open("POST", this.uploaderUrl + '/upload/' + this.sessionId + '/' + destinationFolderBase64 + '/?' + this.defaultParameters, true);
|
||||
xhr.overrideMimeType('text/plain; charset=x-user-defined-binary');
|
||||
|
||||
reader.onload = function(evt) {
|
||||
xhr.send(evt.target.result);
|
||||
};
|
||||
reader.readAsBinaryString(file);
|
||||
};
|
||||
|
||||
|
||||
/* Aggiunge o sovrascrive i metadati di un file. */
|
||||
ARKIWI.Uploader.prototype.metadata = function (jsonKVString, callback) {
|
||||
$.ajax({
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
=============================================================================
|
||||
/*------------------------------------------------------------------------------------------------------------------------*/
|
||||
|
||||
var arkiwi;
|
||||
|
||||
function supportAjaxUploadWithProgress() {
|
||||
return supportFileAPI() && supportAjaxUploadProgressEvents();
|
||||
|
||||
|
@ -34,7 +36,7 @@ function initialize(endpoint) {
|
|||
body.append('<p>HTML 5 upload NOT supported by your browser</p>');
|
||||
}
|
||||
else {
|
||||
var arkiwi = new ARKIWI.Uploader(endpoint);
|
||||
arkiwi = new ARKIWI.Uploader(endpoint);
|
||||
var callbacks = {
|
||||
success: function(id) {
|
||||
//$('#status').html('Session id ' + id);
|
||||
|
@ -48,21 +50,24 @@ function initialize(endpoint) {
|
|||
arkiwi.create(callbacks);
|
||||
}
|
||||
|
||||
/*$('input[id=hiddenfileinput]').bind('change', function() {
|
||||
//this.files[0].size gets the size of your file.
|
||||
$('#fileuploadtotal').text(this.files[0].size + ' bytes.');
|
||||
currentFileName = this.files[0].name;
|
||||
$('input[id=hiddenfileinput]').bind('change', function() {
|
||||
fileInputUpdate(this.files);
|
||||
});
|
||||
};
|
||||
|
||||
function selectFile(e) {
|
||||
$('input[id=hiddenfileinput]').click();
|
||||
e.preventDefault();
|
||||
};
|
||||
|
||||
function fileInputUpdate(files) {
|
||||
//Gestiamo solo un file, non molteplici
|
||||
var file = files[0];
|
||||
$('#file-name').text(file.name);
|
||||
$('#upload-button').prop("disabled", false);
|
||||
|
||||
$('#upload-button').bind('click', function(e) {
|
||||
e.preventDefault();
|
||||
arkiwi.upload5(file);
|
||||
});
|
||||
|
||||
var callbacks = {
|
||||
success: function(id) {
|
||||
//$('#status').html('Session id ' + id);
|
||||
console.log('Session id ' + id);
|
||||
},
|
||||
unauthorized: function() {
|
||||
arkiwi.create(callbacks);
|
||||
},
|
||||
};
|
||||
|
||||
arkiwi.create(callbacks);*/
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue