From 8a5d1ffebe8eb077b43df042314013143698b499 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Sun, 17 Apr 2011 01:17:34 +0200 Subject: [PATCH] fix that might solve strange uploading issues --- files/ajax/upload.php | 3 ++- lib/filestorage.php | 12 ++++++++++++ lib/filesystem.php | 5 +++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/files/ajax/upload.php b/files/ajax/upload.php index 79b6c0b284c..a1b41d6ba23 100644 --- a/files/ajax/upload.php +++ b/files/ajax/upload.php @@ -21,7 +21,8 @@ if(!empty($dir)) $dir .= '/'; $target='/' . stripslashes($dir) . $fileName; if(isset($_SESSION['username']) and $_SESSION['username'] and strpos($dir,'..') === false){ - if(OC_FILESYSTEM::fromTmpFile($source,$target)){ + if(OC_FILESYSTEM::fromUploadedFile($source,$target)){ +// if(OC_FILES::move(dirname($source),basename($source), $dir, $fileName)){ echo json_encode(array( "status" => "success")); exit(); } diff --git a/lib/filestorage.php b/lib/filestorage.php index 799d07da9db..462cc402814 100644 --- a/lib/filestorage.php +++ b/lib/filestorage.php @@ -69,6 +69,7 @@ class OC_FILESTORAGE{ public function fopen($path,$mode){} public function toTmpFile($path){}//copy the file to a temporary file, used for cross-storage file actions public function fromTmpFile($tmpPath,$path){}//copy a file from a temporary file, used for cross-storage file actions + public function fromUploadedFile($tmpPath,$path){}//copy a file from a temporary file, used for cross-storage file actions public function getMimeType($path){} public function delTree($path){} public function find($path){} @@ -388,6 +389,17 @@ die( "oh nooo!" ); return false; } } + + public function fromUploadedFile($tmpFile,$path){ + $fileStats = stat($tmpFile); + if(move_uploaded_file($tmpFile,$this->datadir.$path)){ + touch($this->datadir.$path, $fileStats['mtime'], $fileStats['atime']); + $this->notifyObservers($path,OC_FILEACTION_CREATE); + return true; + }else{ + return false; + } + } public function delTree($dir) { $dirRelative=$dir; diff --git a/lib/filesystem.php b/lib/filesystem.php index 66da4fc3145..54b2ad9ce77 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -339,6 +339,11 @@ class OC_FILESYSTEM{ return $storage->fromTmpFile($tmpFile,self::getInternalPath($path)); } } + static public function fromUploadedFile($tmpFile,$path){ + if(self::canWrite($path) and $storage=self::getStorage($path)){ + return $storage->fromUploadedFile($tmpFile,self::getInternalPath($path)); + } + } static public function getMimeType($path){ if(self::canRead($path) and $storage=self::getStorage($path)){ return $storage->getMimeType(self::getInternalPath($path));