".get_lang('MissingImagesDetected')."
" .""; return $form; } /** * This recursive function can be used during the upgrade process form older * versions of Chamilo * It crawls the given directory, checks if the file is in the DB and adds * it if it's not. * * @param array $courseInfo * @param array $userInfo * @param string $base_work_dir course document dir * @param string $folderPath folder to read * @param int $sessionId * @param int $groupId group.id * @param bool $output * @param array $parent * @param string $whatIfFileExists * * @return bool */ function add_all_documents_in_folder_to_database( $courseInfo, $userInfo, $base_work_dir, $folderPath, $sessionId = 0, $groupId = 0, $output = false, $parent = [], $whatIfFileExists = 'overwrite' ) { if (empty($userInfo) || empty($courseInfo)) { return false; } $userId = $userInfo['user_id']; // Open dir $handle = opendir($folderPath); if (is_dir($folderPath)) { // Run trough while ($file = readdir($handle)) { if ($file == '.' || $file == '..') { continue; } $parentPath = ''; if (!empty($parent) && isset($parent['path'])) { $parentPath = $parent['path']; if ($parentPath == '/') { $parentPath = ''; } } $completePath = $parentPath.'/'.$file; $sysFolderPath = $folderPath.'/'.$file; // Is directory? if (is_dir($sysFolderPath)) { $folderExists = DocumentManager::folderExists( $completePath, $courseInfo, $sessionId, $groupId ); if ($folderExists === true) { switch ($whatIfFileExists) { case 'overwrite': $documentId = DocumentManager::get_document_id($courseInfo, $completePath, $sessionId); if ($documentId) { $newFolderData = DocumentManager::get_document_data_by_id( $documentId, $courseInfo['code'], false, $sessionId ); } break; case 'rename': $newFolderData = create_unexisting_directory( $courseInfo, $userId, $sessionId, $groupId, null, $base_work_dir, $completePath, null, null, true ); break; case 'nothing': if ($output) { $documentId = DocumentManager::get_document_id($courseInfo, $completePath, $sessionId); if ($documentId) { $folderData = DocumentManager::get_document_data_by_id( $documentId, $courseInfo['code'], false, $sessionId ); Display::addFlash( Display::return_message( $folderData['path'].' '.get_lang('UplAlreadyExists'), 'warning' ) ); } } continue 2; break; } } else { $newFolderData = create_unexisting_directory( $courseInfo, $userId, $sessionId, $groupId, null, $base_work_dir, $completePath, null, null, false ); } // Recursive add_all_documents_in_folder_to_database( $courseInfo, $userInfo, $base_work_dir, $sysFolderPath, $sessionId, $groupId, $output, $newFolderData, $whatIfFileExists ); } else { // Rename $uploadedFile = [ 'name' => $file, 'tmp_name' => $sysFolderPath, 'size' => filesize($sysFolderPath), 'type' => null, 'from_file' => true, 'move_file' => true, ]; handle_uploaded_document( $courseInfo, $uploadedFile, $base_work_dir, $parentPath, $userId, $groupId, null, 0, $whatIfFileExists, $output, false, null, $sessionId ); } } } } /** * Get the uploax max filesize from ini php in bytes. * * @return int */ function getIniMaxFileSizeInBytes() { $maxSize = 0; if (preg_match('/^([0-9]+)([a-zA-Z]*)$/', ini_get('upload_max_filesize'), $matches)) { // see http://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes switch (strtoupper($matches['2'])) { case 'G': $maxSize = $matches['1'] * 1073741824; break; case 'M': $maxSize = $matches['1'] * 1048576; break; case 'K': $maxSize = $matches['1'] * 1024; break; default: $maxSize = $matches['1']; } } $maxSize = (int) $maxSize; return $maxSize; }