/** * Saves the file into folders and create the folders if they do not exist * * @param $tags String all the folders name separated by a comma * @param $fid The file ID * @return void */ private function saveFolders($tags, $fid) { $cor = new FilfoldersFilfiles(); $cor->delete("filfiles_id = '" . $fid . "'"); foreach (preg_split('/,/', $tags) as $tag) { if (trim($tag) != '') { $folderLabel = ucfirst(strtolower(trim($tag))); $folderDb = new Filfolders(); $where = "safinstances_id = '" . $this->safinstancesId . "' AND label LIKE '" . addslashes($folderLabel) . "' "; $rows = $folderDb->fetchAll($where); if (count($rows) == 1) { $folderRow = $rows[0]; } elseif (count($rows) == 0) { // create the folder $folderRow = $folderDb->createRow(); $folderRow->label = $folderLabel; $folderRow->safinstances_id = $this->safinstancesId; $folderRow->save(); } else { break; } // add data in the correspondance table $cor = new FilfoldersFilfiles(); $rows2 = $cor->fetchAll("filfolders_id = '" . $folderRow->id . "' AND filfiles_id = '" . $fid . "' "); if (count($rows2) == 0) { $corrE = $cor->createRow(); $corrE->filfolders_id = $folderRow->id; $corrE->filfiles_id = $fid; $corrE->save(); } } } }
/** * Move a file from a directory to the final appdata of the webinstance * and register it to the DB * * @param string $filepath Path to the temp files * @param string $comment Comment to place in the meta description (for search purpose, for ex the name of the user) * @param string $folder The name of the folder to push the files in * @return bool|int */ public function fileToFileManager($filepath = '', $comment = '', $folder = 'temp') { if (!file_exists($filepath)) { return false; } try { $fileObj = Sydney_Medias_Filetypesfactory::createfiletype($filepath); $newName = uniqid() . '_' . Sydney_Medias_Utils::sanitizeFilename($fileObj->basename . '.' . $fileObj->extension); $newPath = Sydney_Tools_Paths::getAppdataPath() . '/adminfiles/' . $fileObj->extension . '/'; if (!is_dir($newPath)) { mkdir($newPath, 0777, true); } rename($filepath, $newPath . $newName); $fileName = $newName; $newFileObj = Sydney_Medias_Filetypesfactory::createfiletype($newPath . $newName); $fileInfo = $newFileObj->getFileinfo(); $fileWeight = $fileInfo['general.filesize']; // On récupère la taille du fichier pour pouvoir l'ajouter en DB $type = $newFileObj->extension; $usersId = Sydney_Tools_User::getUserdata('users_id'); // @todo TODO we ll have to change that, for now it uploads the file as Arnaud (user id 1) if nothing is defined. if ($usersId === false) { $usersId = 1; } $safinstancesId = Sydney_Tools_Sydneyglobals::getSafinstancesId(); // save the file to DB $fileFilesId = $this->registerFileToDb($newPath, $fileName, $fileWeight, $type, $usersId, $safinstancesId, array(), $comment); // put them in the right folder $filefoldersDb = new Filfolders(); $filefoldersId = $filefoldersDb->addSystemFolder($folder); if ($fileFilesId) { $fileCorDb = new FilfoldersFilfiles(); $fileCor = $fileCorDb->createRow(); $fileCor->filfolders_id = $filefoldersId; $fileCor->filfiles_id = $fileFilesId; $fileCor->save(); } // returns the files ids return $fileFilesId; } catch (Exception $e) { Zend_Debug::dump($e->getMessage()); return false; } }