本文整理汇总了PHP中FileManager::create_unexisting_directory方法的典型用法代码示例。如果您正苦于以下问题:PHP FileManager::create_unexisting_directory方法的具体用法?PHP FileManager::create_unexisting_directory怎么用?PHP FileManager::create_unexisting_directory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileManager
的用法示例。
在下文中一共展示了FileManager::create_unexisting_directory方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: error_log
error_log("upload" . $_FILES['Filedata']);
}
/*==== PERMISSION ====*/
$permissions = CourseManager::get_user_in_course_status($user_id, $cidReq);
if ($permissions != COURSEMANAGER) {
if ($debug > 0) {
error_log("Upload from videoconf not allowed !!!", 0);
}
die('Not allowed');
// this user is not allowed to add upload documents
}
/*==== UPLOAD ====*/
$destPath = $coursePath . VIDEOCONF_UPLOAD_PATH;
/*==== creation of /videoconf ====*/
if (!is_dir($destPath)) {
$result = FileManager::create_unexisting_directory($_course, $user_id, api_get_session_id(), 0, null, $coursePath, VIDEOCONF_UPLOAD_PATH);
if (!$result) {
if ($debug > 0) {
error_log("Can't create " . $destPath . " folder", 0);
}
}
}
/*==== file upload ====*/
$newPath = $_FILES['Filedata']['name'];
if ($debug > 0) {
error_log($newPath);
}
/*==== extension extraction ====*/
$file_name = strrpos($newPath, '.') > 0 ? substr($newPath, 0, strrpos($newPath, '.')) : $newPath;
$file_extension = strrpos($newPath, '.') > 0 ? substr($newPath, strrpos($newPath, '.'), 10) : '';
if ($debug > 0) {
示例2: create_group
/**
* Create a group
* @param string $name The name for this group
* @param int $tutor The user-id of the group's tutor
* @param int $places How many people can subscribe to the new group
*/
public static function create_group($name, $category_id, $tutor, $places)
{
$_course = api_get_course_info();
$table_group = Database::get_course_table(TABLE_GROUP);
$session_id = api_get_session_id();
$course_id = api_get_course_int_id();
$currentCourseRepository = $_course['path'];
$category = self::get_category($category_id);
$places = intval($places);
if ($places == 0) {
//if the amount of users per group is not filled in, use the setting from the category
$places = $category['max_student'];
} else {
if ($places > $category['max_student'] && $category['max_student'] != 0) {
$places = $category['max_student'];
}
}
$sql = "INSERT INTO " . $table_group . " SET\n c_id = {$course_id} ,\n category_id='" . Database::escape_string($category_id) . "',\n max_student = '" . $places . "',\n doc_state = '" . $category['doc_state'] . "',\n calendar_state = '" . $category['calendar_state'] . "',\n work_state = '" . $category['work_state'] . "',\n announcements_state = '" . $category['announcements_state'] . "',\n forum_state = '" . $category['forum_state'] . "',\n wiki_state = '" . $category['wiki_state'] . "',\n chat_state = '" . $category['chat_state'] . "',\n self_registration_allowed = '" . $category['self_reg_allowed'] . "',\n self_unregistration_allowed = '" . $category['self_unreg_allowed'] . "',\n session_id='" . Database::escape_string($session_id) . "'";
Database::query($sql);
$lastId = Database::insert_id();
if ($lastId) {
$desired_dir_name = '/' . api_replace_dangerous_char($name, 'strict') . '_groupdocs';
$my_path = api_get_path(SYS_COURSE_PATH) . $currentCourseRepository . '/document';
$unique_name = FileManager::create_unexisting_directory($_course, api_get_user_id(), $session_id, $lastId, NULL, $my_path, $desired_dir_name);
/* Stores the directory path into the group table */
$sql = "UPDATE " . $table_group . " SET name = '" . Database::escape_string($name) . "', secret_directory = '" . $unique_name . "'\n WHERE c_id = {$course_id} AND iid ='" . $lastId . "'";
Database::query($sql);
// create a forum if needed
if ($category['forum_state'] >= 0) {
require_once api_get_path(SYS_CODE_PATH) . 'forum/forumconfig.inc.php';
require_once api_get_path(SYS_CODE_PATH) . 'forum/forumfunction.inc.php';
$forum_categories = get_forum_categories();
$values = array();
$values['forum_title'] = $name;
$values['group_id'] = $lastId;
$counter = 0;
foreach ($forum_categories as $key => $value) {
if ($counter == 0) {
$forum_category_id = $key;
}
$counter++;
}
// A sanity check.
if (empty($forum_category_id)) {
$forum_category_id = 0;
}
$values['forum_category'] = $forum_category_id;
$values['allow_anonymous_group']['allow_anonymous'] = 0;
$values['students_can_edit_group']['students_can_edit'] = 0;
$values['approval_direct_group']['approval_direct'] = 0;
$values['allow_attachments_group']['allow_attachments'] = 1;
$values['allow_new_threads_group']['allow_new_threads'] = 1;
$values['default_view_type_group']['default_view_type'] = api_get_setting('default_forum_view');
$values['group_forum'] = $lastId;
if ($category['forum_state'] == '1') {
$values['public_private_group_forum_group']['public_private_group_forum'] = 'public';
} elseif ($category['forum_state'] == '2') {
$values['public_private_group_forum_group']['public_private_group_forum'] = 'private';
} elseif ($category['forum_state'] == '0') {
$values['public_private_group_forum_group']['public_private_group_forum'] = 'unavailable';
}
store_forum($values);
}
}
return $lastId;
}
示例3: restore_documents
/**
* Restore documents
* @param int session id
*
*/
function restore_documents($session_id = 0, $respect_base_content = false, $destination_course_code = '')
{
$perm = api_get_permissions_for_new_directories();
$course_info = api_get_course_info($destination_course_code);
if ($this->course->has_resources(RESOURCE_DOCUMENT)) {
$table = Database::get_course_table(TABLE_DOCUMENT);
$resources = $this->course->resources;
foreach ($resources[RESOURCE_DOCUMENT] as $id => $document) {
$path = api_get_path(SYS_COURSE_PATH) . $this->course->destination_path . '/';
//$dirs = explode('/', dirname($document->path));
if (empty($document->item_properties[0]['id_session'])) {
$my_session_id = 0;
} else {
$my_session_id = $session_id;
}
if ($document->file_type == FOLDER) {
$visibility = $document->item_properties[0]['visibility'];
if (!empty($document->title)) {
$title = $document->title;
} else {
$title = basename($document->path);
}
$new = substr($document->path, 8);
if (!is_dir($path . 'document' . $new)) {
$created_dir = FileManager::create_unexisting_directory($course_info, api_get_user_id(), $my_session_id, 0, 0, $path . 'document', $new, $title, $visibility);
}
} elseif ($document->file_type == DOCUMENT) {
//Checking if folder exists in the database otherwise we created it
$dir_to_create = dirname($document->path);
if (!empty($dir_to_create) && $dir_to_create != 'document' && $dir_to_create != '/') {
if (is_dir($path . dirname($document->path))) {
$sql = "SELECT id FROM " . $table . " WHERE c_id = " . $this->destination_course_id . " AND path = '/" . self::DBUTF8escapestring(substr(dirname($document->path), 9)) . "'";
$res = Database::query($sql);
if (Database::num_rows($res) == 0) {
//continue;
$visibility = $document->item_properties[0]['visibility'];
$new = '/' . substr(dirname($document->path), 9);
$title = str_replace('/', '', $new);
// This code fixes the possibility for a file without a directory entry to be
$document_id = FileManager::add_document($course_info, $new, 'folder', 0, $title, null, null, false);
api_item_property_update($course_info, TOOL_DOCUMENT, $document_id, 'FolderCreated', $document->item_properties[0]['insert_user_id'], $document->item_properties[0]['to_group_id'], $document->item_properties[0]['to_user_id'], null, null, $my_session_id);
}
} else {
//$created_dir = FileManager::create_unexisting_directory($course_info, api_get_user_id(), $my_session_id, 0, 0 , $path.'document', $new, $title, $visibility, true);
}
}
if (file_exists($path . $document->path)) {
switch ($this->file_option) {
case FILE_OVERWRITE:
$origin_path = $this->course->backup_path . '/' . $document->path;
if (file_exists($origin_path)) {
copy($origin_path, $path . $document->path);
$sql = "SELECT id FROM " . $table . " WHERE c_id = " . $this->destination_course_id . " AND path = '/" . self::DBUTF8escapestring(substr($document->path, 9)) . "'";
$res = Database::query($sql);
$count = Database::num_rows($res);
if ($count == 0) {
$sql = "INSERT INTO {$table} SET\n \t\t\t\t\t\t\t\t\t\t\t\tpath \t\t= '/" . self::DBUTF8escapestring(substr($document->path, 9)) . "',\n \t\t\t\t\t\t\t\t\t\t\t\tc_id \t\t= " . $this->destination_course_id . ",\n \t\t\t\t\t\t\t\t\t\t\t\tcomment \t= '" . self::DBUTF8escapestring($document->comment) . "',\n \t\t\t\t\t\t\t\t\t\t\t\ttitle \t\t= '" . self::DBUTF8escapestring($document->title) . "' ,\n \t\t\t\t\t\t\t\t\t\t\t\tfiletype\t='" . $document->file_type . "',\n \t\t\t\t\t\t\t\t\t\t\t\tsize\t\t= '" . $document->size . "',\n \t\t\t\t\t\t\t\t\t\t\t\tsession_id \t= '{$my_session_id}'";
Database::query($sql);
$document_id = Database::insert_id();
$this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id;
api_item_property_update($course_info, TOOL_DOCUMENT, $document_id, 'DocumentAdded', $document->item_properties[0]['insert_user_id'], $document->item_properties[0]['to_group_id'], $document->item_properties[0]['to_user_id'], null, null, $my_session_id);
} else {
$obj = Database::fetch_object($res);
$sql = "UPDATE " . $table . " SET\n path \t\t= '/" . self::DBUTF8escapestring(substr($document->path, 9)) . "',\n\t\t\t\t\t\t\t\t\t\t\tc_id \t\t= " . $this->destination_course_id . ",\n\t\t\t\t\t\t\t\t\t\t\tcomment \t= '" . self::DBUTF8escapestring($document->comment) . "',\n\t\t\t\t\t\t\t\t\t\t\ttitle \t\t= '" . self::DBUTF8escapestring($document->title) . "' ,\n\t\t\t\t\t\t\t\t\t\t\tfiletype\t='" . $document->file_type . "',\n\t\t\t\t\t\t\t\t\t\t\tsize\t\t= '" . $document->size . "',\n\t\t\t\t\t\t\t\t\t\t\tsession_id \t= '{$my_session_id}'\n WHERE c_id = " . $this->destination_course_id . " AND path = '/" . self::DBUTF8escapestring(substr($document->path, 9)) . "'";
Database::query($sql);
api_item_property_update($course_info, TOOL_DOCUMENT, $obj->id, 'default', $document->item_properties[0]['insert_user_id'], $document->item_properties[0]['to_group_id'], $document->item_properties[0]['to_user_id'], null, null, $my_session_id);
}
}
//Replace old course code with the new destination code
$file_info = pathinfo($path . $document->path);
if (in_array($file_info['extension'], array('html', 'htm'))) {
$content = file_get_contents($path . $document->path);
if (UTF8_CONVERT) {
$content = utf8_encode($content);
}
$content = DocumentManager::replace_urls_inside_content_html_from_copy_course($content, $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']);
$result = file_put_contents($path . $document->path, $content);
}
$sql = "SELECT id FROM " . $table . " WHERE c_id = " . $this->destination_course_id . " AND path='/" . substr($document->path, 9) . "'";
$res = Database::query($sql);
$obj = Database::fetch_object($res);
$this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $obj->id;
$sql = "UPDATE " . $table . " SET comment = '" . self::DBUTF8escapestring($document->comment) . "', title='" . self::DBUTF8escapestring($document->title) . "', size='" . $document->size . "'\n\t\t\t\t\t\t\t\t\t\tWHERE c_id = " . $this->destination_course_id . " AND id = '" . $obj->id . "'";
Database::query($sql);
break;
case FILE_SKIP:
$sql = "SELECT id FROM " . $table . " WHERE c_id = " . $this->destination_course_id . " AND path='/" . self::DBUTF8escapestring(substr($document->path, 9)) . "'";
$res = Database::query($sql);
$obj = Database::fetch_object($res);
$this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $obj->id;
break;
case FILE_RENAME:
$i = 1;
$ext = explode('.', basename($document->path));
if (count($ext) > 1) {
//.........这里部分代码省略.........
示例4: generate_lp_folder
public function generate_lp_folder($course, $lp_name = null)
{
$filepath = '';
$dir = '/learning_path/';
if (empty($lp_name)) {
$lp_name = $this->name;
}
$folder = self::generate_learning_path_folder($course);
//Creating LP folder
if ($folder) {
//Limits title size
$title = api_substr(api_replace_dangerous_char($lp_name), 0, 80);
$dir = $dir . $title;
$filepath = api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document';
if (!is_dir($filepath . '/' . $dir)) {
$folder = FileManager::create_unexisting_directory($course, api_get_user_id(), 0, 0, 0, $filepath, $dir, $lp_name);
} else {
$folder = true;
}
$dir = $dir . '/';
if ($folder) {
$filepath = api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document' . $dir;
}
}
$array = array('dir' => $dir, 'filepath' => $filepath, 'folder' => $folder);
return $array;
}
示例5: create_directory_certificate_in_course
/**
* Create directory certificate
* @param string The course id
* @return void()
*/
static function create_directory_certificate_in_course($course_id)
{
$course_info = api_get_course_info($course_id);
if (!empty($course_info)) {
$to_group_id = 0;
$to_user_id = null;
$course_dir = $course_info['path'] . "/document/";
$sys_course_path = api_get_path(SYS_COURSE_PATH);
$base_work_dir = $sys_course_path . $course_dir;
$base_work_dir_test = $base_work_dir . 'certificates';
$dir_name = '/certificates';
$post_dir_name = get_lang('CertificatesFiles');
$visibility_command = 'invisible';
if (!is_dir($base_work_dir_test)) {
$created_dir = FileManager::create_unexisting_directory($course_info, api_get_user_id(), api_get_session_id(), $to_group_id, $to_user_id, $base_work_dir, $dir_name, $post_dir_name);
$update_id = self::get_document_id_of_directory_certificate();
api_item_property_update($course_info, TOOL_DOCUMENT, $update_id, $visibility_command, api_get_user_id());
}
}
}
示例6: api_get_course_id
if (isset($_POST['create_dir']) && $_POST['dirname'] != '') {
// Needed for directory creation
$post_dir_name = $_POST['dirname'];
if ($post_dir_name == '../' || $post_dir_name == '.' || $post_dir_name == '..') {
Display::display_error_message(get_lang('CannotCreateDir'));
} else {
if (!empty($_POST['dir_id'])) {
$document_data = DocumentManager::get_document_data_by_id($_POST['dir_id'], api_get_course_id());
$curdirpath = $document_data['path'];
}
$added_slash = $curdirpath == '/' ? '' : '/';
$dir_name = $curdirpath . $added_slash . api_replace_dangerous_char($post_dir_name);
$dir_name = FileManager::disable_dangerous_file($dir_name);
$dir_check = $base_work_dir . $dir_name;
if (!is_dir($dir_check)) {
$created_dir = FileManager::create_unexisting_directory($_course, api_get_user_id(), api_get_session_id(), $to_group_id, $to_user_id, $base_work_dir, $dir_name, $post_dir_name);
if ($created_dir) {
Display::display_confirmation_message('<span title="' . $created_dir . '">' . get_lang('DirCr') . '</span>', false);
// Uncomment if you want to enter the created dir
//$curdirpath = $created_dir;
//$curdirpathurl = urlencode($curdirpath);
} else {
Display::display_error_message(get_lang('CannotCreateDir'));
}
} else {
Display::display_error_message(get_lang('CannotCreateDir'));
}
}
}
// Show them the form for the directory name
if (isset($_GET['createdir'])) {
示例7: str_replace
//create a directory for the missing files
$img_directory = str_replace('.', '_', $_POST['related_file'] . "_files");
$missing_files_dir = FileManager::create_unexisting_directory($_course, $_user['user_id'], api_get_session_id(), $to_group_id, $to_user_id, $base_work_dir, $img_directory);
//put the uploaded files in the new directory and get the paths
$paths_to_replace_in_file = FileManager::move_uploaded_file_collection_into_directory($_course, $_FILES['img_file'], $base_work_dir, $missing_files_dir, $_user['user_id'], $to_group_id, $to_user_id, $max_filled_space);
//open the html file and replace the paths
FileManager::replace_img_path_in_html_file($_POST['img_file_path'], $paths_to_replace_in_file, $base_work_dir . $_POST['related_file']);
//update parent folders
FileManager::item_property_update_on_folder($_course, $_POST['curdirpath'], $_user['user_id']);
}
}
//they want to create a directory
if (isset($_POST['create_dir']) && $_POST['dirname'] != '') {
$added_slash = $path == '/' ? '' : '/';
$dir_name = $path . $added_slash . api_replace_dangerous_char($_POST['dirname']);
$created_dir = FileManager::create_unexisting_directory($_course, $_user['user_id'], api_get_session_id(), $to_group_id, $to_user_id, $base_work_dir, $dir_name, $_POST['dirname']);
if ($created_dir) {
//Display::display_normal_message("<strong>".$created_dir."</strong> was created!");
Display::display_normal_message(get_lang('DirCr'));
$path = $created_dir;
} else {
display_error(get_lang('CannotCreateDir'));
}
}
if (isset($_GET['createdir'])) {
//create the form that asks for the directory name
$new_folder_text = '<form action="' . api_get_self() . '" method="POST">';
$new_folder_text .= '<input type="hidden" name="curdirpath" value="' . $path . '"/>';
$new_folder_text .= get_lang('NewDir') . ' ';
$new_folder_text .= '<input type="text" name="dirname"/>';
$new_folder_text .= '<input type="submit" name="create_dir" value="' . get_lang('Ok') . '"/>';