Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Fix PlUploader for access.ftp and similar ones
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Jul 31, 2014
1 parent cc2a99d commit 0f78b5e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
39 changes: 33 additions & 6 deletions core/src/plugins/uploader.plupload/class.PluploadProcessor.php
Expand Up @@ -45,7 +45,9 @@ class PluploadProcessor extends AJXP_Plugin

public function unifyChunks($action, &$httpVars, &$fileVars)
{
$filename = SystemTextEncoding::fromUTF8($httpVars["name"]);

$filename = AJXP_Utils::decodeSecureMagic($httpVars["name"]);

$tmpName = $fileVars["file"]["tmp_name"];
$chunk = $httpVars["chunk"];
$chunks = $httpVars["chunks"];
Expand All @@ -58,9 +60,26 @@ public function unifyChunks($action, &$httpVars, &$fileVars)
}
$plugin = AJXP_PluginsService::findPlugin("access", $repository->getAccessType());
$streamData = $plugin->detectStreamWrapper(true);
$dir = $httpVars["dir"];
$dir = AJXP_Utils::securePath($httpVars["dir"]);
$destStreamURL = $streamData["protocol"]."://".$repository->getId().$dir."/";

$driver = ConfService::loadDriverForRepository($repository);
$remote = false;
if (method_exists($driver, "storeFileToCopy")) {
$remote = true;
$destCopy = AJXP_XMLWriter::replaceAjxpXmlKeywords($repository->getOption("TMP_UPLOAD"));
// Make tmp folder a bit more unique using secure_token
$tmpFolder = $destCopy."/".$httpVars["secure_token"];
if(!is_dir($tmpFolder)){
@mkdir($destCopy."/".$httpVars["secure_token"], 0700, true);
}
$target = $tmpFolder.'/'.$filename;
$fileVars["file"]["destination"] = base64_encode($dir);
}else{
$target = $destStreamURL.$filename;
}


//error_log("Directory: ".$dir);

// Clean the fileName for security reasons
Expand All @@ -79,7 +98,7 @@ public function unifyChunks($action, &$httpVars, &$fileVars)
//error_log("tmpName: ".$tmpName);

// Open temp file
$out = fopen($destStreamURL.$filename, $chunk == 0 ? "wb" : "ab");
$out = fopen($target, $chunk == 0 ? "wb" : "ab");
if ($out) {
// Read binary input stream and append it to temp file
$in = fopen($tmpName, "rb");
Expand All @@ -98,7 +117,7 @@ public function unifyChunks($action, &$httpVars, &$fileVars)
die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}');
} else {
// Open temp file
$out = fopen($destStreamURL.$filename, $chunk == 0 ? "wb" : "ab");
$out = fopen($target, $chunk == 0 ? "wb" : "ab");
if ($out) {
// Read binary input stream and append it to temp file
$in = fopen("php://input", "rb");
Expand All @@ -115,8 +134,16 @@ public function unifyChunks($action, &$httpVars, &$fileVars)
die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}');
}
/* we apply the hook if we are uploading the last chunk */
if($chunk == $chunks-1)
AJXP_Controller::applyHook("node.change", array(null, new AJXP_Node($destStreamURL.$filename), false));
if($chunk == $chunks-1){
if(!$remote){
AJXP_Controller::applyHook("node.change", array(null, new AJXP_Node($destStreamURL.$filename), false));
}else{
$fileVars["file"]["tmp_name"] = $target;
$fileVars["file"]["name"] = $filename;
$driver->storeFileToCopy($fileVars["file"]);
AJXP_Controller::findActionAndApply("next_to_remote", array(), array());
}
}
// Return JSON-RPC response
die('{"jsonrpc" : "2.0", "result" : null, "id" : "id"}');
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/uploader.plupload/pluploader_tpl.html
Expand Up @@ -97,7 +97,7 @@
});
Uploader.bind('FileUploaded', function(up, file, res) {
if(this.total.queued <= 1) {
parent.ajaxplorer.fireContextRefresh();
//parent.ajaxplorer.fireContextRefresh();
parent.document.fire("ajaxplorer:longtask_finished");
}
$.get(upurl);
Expand Down

0 comments on commit 0f78b5e

Please sign in to comment.