private function importBulkResumes() { if (!isset($_SESSION['CATS']) || empty($_SESSION['CATS'])) { CommonErrors::fatal(COMMONERROR_NOTLOGGEDIN, $this); } if ($_SESSION['CATS']->getAccessLevel() < ACCESS_LEVEL_SA) { CommonErrors::fatal(COMMONERROR_PERMISSION, $this); } $uploadPath = FileUtility::getUploadPath($this->_siteID, 'massimport'); $attachments = new Attachments($this->_siteID); $bulkResumes = $attachments->getBulkAttachments(); if (!count($bulkResumes)) { CommonErrors::fatal(COMMONERROR_BADINDEX, $this); } /** * Write the parsed resume contents to the new file which will * be created as a text document for each bulk attachment. */ foreach ($bulkResumes as $bulkResume) { $fullName = $bulkResume['originalFileName']; if (!strlen(trim($fullName))) { $fullName = 'Untitled'; } $mp = explode('.', $fullName); $fileName = implode('.', array_slice($mp, 0, -1)); if (!@file_exists($newFileName = $uploadPath . '/_BulkResume_' . $fileName . '.txt')) { // Some old files are fulltext encoded which makes them a pain for the parser, fixing here: $contents = DatabaseSearch::fulltextDecode($bulkResume['text']); @file_put_contents($newFileName, $contents); chmod($newFileName, 0777); } } CATSUtility::transferRelativeURI('m=import&a=massImport&step=2'); }
public function wizard_import() { if (!isset($_SESSION['CATS']) || empty($_SESSION['CATS'])) { echo 'CATS has lost your session!'; return; } $siteID = $_SESSION['CATS']->getSiteID(); // Echos Ok to redirect to the import stage, or Fail to go to home module $files = ImportUtility::getDirectoryFiles(FileUtility::getUploadPath($siteID, 'massimport')); if (count($files)) { echo 'Ok'; } else { echo 'Fail'; } }
/** * Store the contents of a file upload in the site's upload directory with an * optional sub-directory and return the name of the file (not including path). * * @param integer ID of the site containing the file * @param string Optional sub-directory to place the file * @param string Index of the $_FILES array (name from the <input> tag) * @return string Complete name of the file (not including path) */ public static function getUploadFileFromPost($siteID, $subDirectory, $id) { if (isset($_FILES[$id])) { if (!@file_exists($_FILES[$id]['tmp_name'])) { // File was removed, accessed from another window, or no longer exists return false; } if (!eval(Hooks::get('FILE_UTILITY_SPACE_CHECK'))) { return; } $uploadPath = FileUtility::getUploadPath($siteID, $subDirectory); $newFileName = $_FILES[$id]['name']; // Could just while(file_exists) it, but I'm paranoid of infinate loops // Shouldn't have 1000 files of the same name anyway for ($i = 0; @file_exists($uploadPath . '/' . $newFileName) && $i < 1000; $i++) { $mp = explode('.', $newFileName); $fileNameBase = implode('.', array_slice($mp, 0, count($mp) - 1)); $fileNameExt = $mp[count($mp) - 1]; if (preg_match('/(.*)_Copy([0-9]{1,3})$/', $fileNameBase, $matches)) { // Copy already appending, increase the # $fileNameBase = sprintf('%s_Copy%d', $matches[1], intval($matches[2]) + 1); } else { $fileNameBase .= '_Copy1'; } $newFileName = $fileNameBase . '.' . $fileNameExt; } if (@move_uploaded_file($_FILES[$id]['tmp_name'], $uploadPath . '/' . $newFileName) && @chmod($uploadPath . '/' . $newFileName, 0777)) { return $newFileName; } } return false; }