/** * stores a new resource in disk * * @param ownerId The id of the owner of this file * @param albumId The album id to which the * @param upload a FileUpload object with information about the * uploaded file */ function storeUpload($resourceId, $ownerId, $upload) { // check that the folders exist if (!$this->_checkBaseStorageFolder()) { return false; } if (!$this->_checkUserStorageFolder($ownerId)) { return false; } // new name for the file $fileParts = explode(".", $upload->getFileName()); $fileExt = $fileParts[count($fileParts) - 1]; $fileName = "{$ownerId}-{$resourceId}.{$fileExt}"; $filePath = $this->getUserFolder($ownerId); // move the file to the temporaray folder first $config =& Config::getConfig(); $tmpFolder = $config->getValue("temp_folder"); /*$files = HttpVars::getFiles();*/ // we don't need the parameter in the constructor though it is necessary // according to the signature of the method $uploads = new FileUploads(null); $result = $uploads->processFile($upload, $tmpFolder); if ($result < 0) { return $result; } // rename it while it's there $origFile = $tmpFolder . "/" . basename($upload->getTmpName()); //do not use storeFile method because I have change filename in $tmpFolder. //$destFile = $this->storeFile( $resourceId, $ownerId, $origFile, RESOURCE_STORAGE_STORE_MOVE ); //$destFile use $filePath and $fileName generated above. $destFile = $filePath . $fileName; //========================================= //codes below are copy and modify from method storeFile // first of all, check if the file is readable and if not, quit if (!File::isReadable($origFile)) { return false; } $res = File::rename($origFile, $destFile); if (!$res) { return false; } // check that the permissions are correct File::chMod($destFile, 0755); //========================================= return $destFile; }