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

Commit

Permalink
Fix #465, PLUploader chunking on FTP, S3, SMB & Dropbox
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Jul 31, 2014
1 parent 0f78b5e commit e6bf981
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
2 changes: 1 addition & 1 deletion core/src/plugins/access.fs/class.fsAccessDriver.php
Expand Up @@ -753,7 +753,7 @@ public function switchAction($action, $httpVars, $fileVars)
return array("ERROR" => array("CODE" => $errorCode, "MESSAGE" => $errorMessage));
} else {
$this->logDebug("Return success");
if($already_existed){
if(isSet($already_existed) && $already_existed === true){
return array("SUCCESS" => true, "UPDATED_NODE" => $createdNode);
}else{
return array("SUCCESS" => true, "CREATED_NODE" => $createdNode);
Expand Down
5 changes: 5 additions & 0 deletions core/src/plugins/access.s3/class.s3AccessDriver.php
Expand Up @@ -90,6 +90,11 @@ public function isWriteable($dir, $type="dir")
return true;
}

public static function isRemote()
{
return true;
}

public function loadNodeInfo(&$node, $parentNode = false, $details = false)
{
parent::loadNodeInfo($node, $parentNode, $details);
Expand Down
29 changes: 24 additions & 5 deletions core/src/plugins/uploader.plupload/class.PluploadProcessor.php
Expand Up @@ -60,6 +60,7 @@ public function unifyChunks($action, &$httpVars, &$fileVars)
}
$plugin = AJXP_PluginsService::findPlugin("access", $repository->getAccessType());
$streamData = $plugin->detectStreamWrapper(true);
$wrapperName = $streamData["classname"];
$dir = AJXP_Utils::securePath($httpVars["dir"]);
$destStreamURL = $streamData["protocol"]."://".$repository->getId().$dir."/";

Expand All @@ -71,11 +72,19 @@ public function unifyChunks($action, &$httpVars, &$fileVars)
// 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);
@mkdir($tmpFolder, 0700, true);
}
$target = $tmpFolder.'/'.$filename;
$fileVars["file"]["destination"] = base64_encode($dir);
}else if(call_user_func(array($wrapperName, "isRemote"))){
$remote = true;
$tmpFolder = AJXP_Utils::getAjxpTmpDir()."/".$httpVars["secure_token"];
if(!is_dir($tmpFolder)){
@mkdir($tmpFolder, 0700, true);
}
$target = $tmpFolder.'/'.$filename;
}else{

$target = $destStreamURL.$filename;
}

Expand Down Expand Up @@ -138,10 +147,20 @@ public function unifyChunks($action, &$httpVars, &$fileVars)
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());
if(method_exists($driver, "storeFileToCopy")){
$fileVars["file"]["tmp_name"] = $target;
$fileVars["file"]["name"] = $filename;
$driver->storeFileToCopy($fileVars["file"]);
AJXP_Controller::findActionAndApply("next_to_remote", array(), array());
}else{
// Remote Driver case: copy temp file to destination
$node = new AJXP_Node($destStreamURL.$filename);
AJXP_Controller::applyHook("node.before_create", array($node, filesize($target)));
AJXP_Controller::applyHook("node.before_change", array(new AJXP_Node($destStreamURL)));
$res = copy($target, $destStreamURL.$filename);
if($res) @unlink($target);
AJXP_Controller::applyHook("node.change", array(null, $node, false));
}
}
}
// Return JSON-RPC response
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 e6bf981

Please sign in to comment.