当前位置: 首页>>代码示例>>PHP>>正文


PHP add_ext_on_mime函数代码示例

本文整理汇总了PHP中add_ext_on_mime函数的典型用法代码示例。如果您正苦于以下问题:PHP add_ext_on_mime函数的具体用法?PHP add_ext_on_mime怎么用?PHP add_ext_on_mime使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了add_ext_on_mime函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: save_message_attachment_file

 /**
  * Saves a message attachment files
  * @param  array 	$_FILES['name']
  * @param  string  	a comment about the uploaded file
  * @param  int		message id
  * @param  int		receiver user id (optional)
  * @param  int		sender user id (optional)
  * @param  int		group id (optional)
  * @return void
  */
 public static function save_message_attachment_file($file_attach, $file_comment, $message_id, $receiver_user_id = 0, $sender_user_id = 0, $group_id = 0)
 {
     $tbl_message_attach = Database::get_main_table(TABLE_MESSAGE_ATTACHMENT);
     // Try to add an extension to the file if it hasn't one
     $new_file_name = add_ext_on_mime(stripslashes($file_attach['name']), $file_attach['type']);
     // user's file name
     $file_name = $file_attach['name'];
     if (!filter_extension($new_file_name)) {
         Display::display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
     } else {
         $new_file_name = uniqid('');
         if (!empty($receiver_user_id)) {
             $message_user_id = $receiver_user_id;
         } else {
             $message_user_id = $sender_user_id;
         }
         // User-reserved directory where photos have to be placed.
         if (!empty($group_id)) {
             $path_user_info = GroupPortalManager::get_group_picture_path_by_id($group_id, 'system', true);
         } else {
             $path_user_info = UserManager::get_user_picture_path_by_id($message_user_id, 'system', true);
         }
         $path_message_attach = $path_user_info['dir'] . 'message_attachments/';
         // If this directory does not exist - we create it.
         if (!file_exists($path_message_attach)) {
             @mkdir($path_message_attach, api_get_permissions_for_new_directories(), true);
         }
         $new_path = $path_message_attach . $new_file_name;
         if (is_uploaded_file($file_attach['tmp_name'])) {
             @copy($file_attach['tmp_name'], $new_path);
         }
         $safe_file_comment = Database::escape_string($file_comment);
         $safe_file_name = Database::escape_string($file_name);
         $safe_new_file_name = Database::escape_string($new_file_name);
         // Storing the attachments if any
         $sql = "INSERT INTO {$tbl_message_attach}(filename,comment, path,message_id,size)\n\t\t\t\t    VALUES ('{$safe_file_name}', '{$safe_file_comment}', '{$safe_new_file_name}' , '{$message_id}', '" . $file_attach['size'] . "' )";
         Database::query($sql);
     }
 }
开发者ID:annickvdp,项目名称:Chamilo1.9.10,代码行数:49,代码来源:message.lib.php

示例2: SanitizeFileName

function SanitizeFileName($sNewFileName, $sMimeType = null)
{
    global $Config;
    if (empty($sMimeType)) {
        $sNewFileName = stripslashes($sNewFileName);
    } else {
        $sNewFileName = add_ext_on_mime(stripslashes($sNewFileName), $sMimeType);
    }
    // Replace dots in the name with underscores (only one dot can be there... security issue).
    if ($Config['ForceSingleExtension']) {
        $sNewFileName = preg_replace('/\\.(?![^.]*$)/', '_', $sNewFileName);
    }
    // Remove \ / | : ? * " < >
    //$sNewFileName = preg_replace( '/\\\\|\\/|\\||\\:|\\?|\\*|"|<|>|[[:cntrl:]]/', '_', $sNewFileName ) ;
    $sNewFileName = replace_dangerous_char($sNewFileName, 'strict');
    $sNewFileName = php2phps($sNewFileName);
    return $sNewFileName;
}
开发者ID:annickvdp,项目名称:Chamilo1.9.10,代码行数:18,代码来源:io.php

示例3: api_get_course_info

$_course = api_get_course_info();
$currentCourseRepositorySys = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/';
$succeed = false;
if ($form->validate()) {
    if ($student_can_edit_in_session && $check) {
        // Check the token inserted into the form
        if (isset($_POST['submitWork'])) {
            $url = null;
            $contains_file = 0;
            $title = isset($_POST['title']) ? $_POST['title'] : null;
            $description = isset($_POST['description']) ? $_POST['description'] : null;
            if ($_POST['contains_file'] && !empty($_FILES['file']['size'])) {
                $updir = $currentCourseRepositorySys . 'work/';
                //directory path to upload
                // Try to add an extension to the file if it has'nt one
                $new_file_name = add_ext_on_mime(stripslashes($_FILES['file']['name']), $_FILES['file']['type']);
                // Replace dangerous characters
                $new_file_name = replace_dangerous_char($new_file_name, 'strict');
                // Transform any .php file in .phps fo security
                $new_file_name = php2phps($new_file_name);
                $filesize = filesize($_FILES['file']['tmp_name']);
                if (empty($filesize)) {
                    $error_message .= Display::return_message(get_lang('UplUploadFailedSizeIsZero'), 'error');
                    $succeed = false;
                } elseif (!filter_extension($new_file_name)) {
                    //filter extension
                    $error_message .= Display::return_message(get_lang('UplUnableToSaveFileFilteredExtension'), 'error');
                    $succeed = false;
                }
                if (!$title) {
                    $title = $_FILES['file']['name'];
开发者ID:ilosada,项目名称:chamilo-lms-icpna,代码行数:31,代码来源:upload.php

示例4: treat_uploaded_file

/**
 *
 * @author Hugues Peeters <hugues.peeters@claroline.net>
 *
 * @param  array $uploaded_file - follows the $_FILES Structure
 * @param  string $base_work_dir - base working directory of the module
 * @param  string $upload_path  - destination of the upload.
 *                               This path is to append to $base_work_dir
 * @param  int $max_filled_space - amount of bytes to not exceed in the base
 *                               working directory
 *
 * @return boolean true if it succeds, false otherwise
 */
function treat_uploaded_file($uploaded_file, $base_work_dir, $upload_path, $max_filled_space, $uncompress = '')
{
    $uploaded_file['name'] = stripslashes($uploaded_file['name']);
    if (!enough_size($uploaded_file['size'], $base_work_dir, $max_filled_space)) {
        return api_failure::set_failure('not_enough_space');
    }
    if ($uncompress == 'unzip' && preg_match('/.zip$/', strtolower($uploaded_file['name']))) {
        return unzip_uploaded_file($uploaded_file, $upload_path, $base_work_dir, $max_filled_space);
    } else {
        $file_name = trim($uploaded_file['name']);
        // CHECK FOR NO DESIRED CHARACTERS
        $file_name = api_replace_dangerous_char($file_name, 'strict');
        // TRY TO ADD AN EXTENSION TO FILES WITOUT EXTENSION
        $file_name = add_ext_on_mime($file_name, $uploaded_file['type']);
        // HANDLE PHP FILES
        $file_name = $file_name;
        // COPY THE FILE TO THE DESIRED DESTINATION
        if (move_uploaded_file($uploaded_file['tmp_name'], $base_work_dir . $upload_path . '/' . $file_name)) {
            set_default_settings($upload_path, $file_name);
        }
        return true;
    }
}
开发者ID:daffef,项目名称:chamilo-lms,代码行数:36,代码来源:fileUpload.lib.php

示例5: save_message_attachment_file

 /**
  * Saves a message attachment files
  * @param  array 	$file_attach $_FILES['name']
  * @param  string  	a comment about the uploaded file
  * @param  int		message id
  * @param  int		receiver user id (optional)
  * @param  int		sender user id (optional)
  * @param  int		group id (optional)
  * @return void
  */
 public static function save_message_attachment_file($file_attach, $file_comment, $message_id, $receiver_user_id = 0, $sender_user_id = 0, $group_id = 0)
 {
     $tbl_message_attach = Database::get_main_table(TABLE_MESSAGE_ATTACHMENT);
     // Try to add an extension to the file if it hasn't one
     $new_file_name = add_ext_on_mime(stripslashes($file_attach['name']), $file_attach['type']);
     // user's file name
     $file_name = $file_attach['name'];
     if (!filter_extension($new_file_name)) {
         Display::display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
     } else {
         $new_file_name = uniqid('');
         if (!empty($receiver_user_id)) {
             $message_user_id = $receiver_user_id;
         } else {
             $message_user_id = $sender_user_id;
         }
         // User-reserved directory where photos have to be placed.*
         $userGroup = new UserGroup();
         if (!empty($group_id)) {
             $path_user_info = $userGroup->get_group_picture_path_by_id($group_id, 'system', true);
         } else {
             $path_user_info['dir'] = UserManager::getUserPathById($message_user_id, 'system');
         }
         $path_message_attach = $path_user_info['dir'] . 'message_attachments/';
         // If this directory does not exist - we create it.
         if (!file_exists($path_message_attach)) {
             @mkdir($path_message_attach, api_get_permissions_for_new_directories(), true);
         }
         $new_path = $path_message_attach . $new_file_name;
         if (is_uploaded_file($file_attach['tmp_name'])) {
             @copy($file_attach['tmp_name'], $new_path);
         }
         // Storing the attachments if any
         $params = ['filename' => $file_name, 'comment' => $file_comment, 'path' => $new_file_name, 'message_id' => $message_id, 'size' => $file_attach['size']];
         Database::insert($tbl_message_attach, $params);
     }
 }
开发者ID:omaoibrahim,项目名称:chamilo-lms,代码行数:47,代码来源:message.lib.php

示例6: elseif

             $vis = $result->visible;
             Database::get()->query("DELETE FROM document WHERE\n                                                 {$group_sql} AND\n                                                 path = ?s", $file_path);
         } else {
             $error = $langFileExists;
         }
     }
 }
 if ($error) {
     $action_message .= "<div class='alert alert-danger'>{$error}</div><br>";
 } elseif ($uploaded) {
     // No errors, so proceed with upload
     // File date is current date
     $file_date = date("Y\\-m\\-d G\\:i\\:s");
     // Try to add an extension to files witout extension,
     // change extension of PHP files
     $fileName = php2phps(add_ext_on_mime($fileName));
     // File name used in file system and path field
     $safe_fileName = safe_filename(get_file_extension($fileName));
     if ($uploadPath == '.') {
         $file_path = '/' . $safe_fileName;
     } else {
         $file_path = $uploadPath . '/' . $safe_fileName;
     }
     if ($extra_path or isset($userFile) and @copy($userFile, $basedir . $file_path)) {
         $vis = 1;
         $file_format = get_file_extension($fileName);
         $id = Database::get()->query("INSERT INTO document SET\n                                        course_id = ?d,\n                                        subsystem = ?d,\n                                        subsystem_id = ?d,\n                                        path = ?s,\n                                        extra_path = ?s,\n                                        filename = ?s,\n                                        visible = ?d,\n                                        comment = ?s,\n                                        category = ?d,\n                                        title = ?s,\n                                        creator = ?s,\n                                        date = ?t,\n                                        date_modified = ?t,\n                                        subject = ?s,\n                                        description = ?s,\n                                        author = ?s,\n                                        format = ?s,\n                                        language = ?s,\n                                        copyrighted = ?d", $course_id, $subsystem, $subsystem_id, $file_path, $extra_path, $fileName, $vis, $_POST['file_comment'], $_POST['file_category'], $_POST['file_title'], $_POST['file_creator'], $file_date, $file_date, $_POST['file_subject'], $_POST['file_description'], $_POST['file_author'], $file_format, $_POST['file_language'], $_POST['file_copyrighted'])->lastInsertID;
         Indexer::queueAsync(Indexer::REQUEST_STORE, Indexer::RESOURCE_DOCUMENT, $id);
         // Logging
         Log::record($course_id, MODULE_ID_DOCS, LOG_INSERT, array('id' => $id, 'filepath' => $file_path, 'filename' => $fileName, 'comment' => $_POST['file_comment'], 'title' => $_POST['file_title']));
         Session::Messages($langDownloadEnd, 'alert-success');
开发者ID:kostastzo,项目名称:openeclass,代码行数:31,代码来源:index.php

示例7: store_add_dropbox

/**
 * @return array|null|string
 */
function store_add_dropbox()
{
    $_course = api_get_course_info();
    $_user = api_get_user_info();
    $dropbox_cnf = getDropboxConf();
    // Validating the form data
    // there are no recipients selected
    if (!isset($_POST['recipients']) || count($_POST['recipients']) <= 0) {
        return get_lang('YouMustSelectAtLeastOneDestinee');
    } else {
        // Check if all the recipients are valid
        $thisIsAMailing = false;
        $thisIsJustUpload = false;
        foreach ($_POST['recipients'] as $rec) {
            if ($rec == 'mailing') {
                $thisIsAMailing = true;
            } elseif ($rec == 'upload') {
                $thisIsJustUpload = true;
            } elseif (strpos($rec, 'user_') === 0 && !isCourseMember(substr($rec, strlen('user_')))) {
                return get_lang('InvalideUserDetected');
            } elseif (strpos($rec, 'group_') !== 0 && strpos($rec, 'user_') !== 0) {
                return get_lang('InvalideGroupDetected');
            }
        }
    }
    // we are doing a mailing but an additional recipient is selected
    if ($thisIsAMailing && count($_POST['recipients']) != 1) {
        return get_lang('MailingSelectNoOther');
    }
    // we are doing a just upload but an additional recipient is selected.
    // note: why can't this be valid? It is like sending a document to yourself AND to a different person (I do this quite often with my e-mails)
    if ($thisIsJustUpload && count($_POST['recipients']) != 1) {
        return get_lang('MailingJustUploadSelectNoOther');
    }
    if (empty($_FILES['file']['name'])) {
        $error = true;
        return get_lang('NoFileSpecified');
    }
    // are we overwriting a previous file or sending a new one
    $dropbox_overwrite = false;
    if (isset($_POST['cb_overwrite']) && $_POST['cb_overwrite']) {
        $dropbox_overwrite = true;
    }
    // doing the upload
    $dropbox_filename = $_FILES['file']['name'];
    $dropbox_filesize = $_FILES['file']['size'];
    $dropbox_filetype = $_FILES['file']['type'];
    $dropbox_filetmpname = $_FILES['file']['tmp_name'];
    // check if the filesize does not exceed the allowed size.
    if ($dropbox_filesize <= 0 || $dropbox_filesize > $dropbox_cnf['maxFilesize']) {
        return get_lang('DropboxFileTooBig');
        // TODO: The "too big" message does not fit in the case of uploading zero-sized file.
    }
    // check if the file is actually uploaded
    if (!is_uploaded_file($dropbox_filetmpname)) {
        // check user fraud : no clean error msg.
        return get_lang('TheFileIsNotUploaded');
    }
    $upload_ok = process_uploaded_file($_FILES['file'], true);
    if (!$upload_ok) {
        return null;
    }
    // Try to add an extension to the file if it hasn't got one
    $dropbox_filename = add_ext_on_mime($dropbox_filename, $dropbox_filetype);
    // Replace dangerous characters
    $dropbox_filename = replace_dangerous_char($dropbox_filename);
    // Transform any .php file in .phps fo security
    $dropbox_filename = php2phps($dropbox_filename);
    //filter extension
    if (!filter_extension($dropbox_filename)) {
        return get_lang('UplUnableToSaveFileFilteredExtension');
    }
    // set title
    $dropbox_title = $dropbox_filename;
    // set author
    if (!isset($_POST['authors'])) {
        $_POST['authors'] = getUserNameFromId($_user['user_id']);
    }
    // note: I think we could better migrate everything from here on to separate functions: store_new_dropbox, store_new_mailing, store_just_upload
    if ($dropbox_overwrite) {
        $dropbox_person = new Dropbox_Person($_user['user_id'], api_is_course_admin(), api_is_course_tutor());
        foreach ($dropbox_person->sentWork as $w) {
            if ($w->title == $dropbox_filename) {
                if ($w->recipients[0]['id'] > dropbox_cnf('mailingIdBase') xor $thisIsAMailing) {
                    return get_lang('MailingNonMailingError');
                }
                if ($w->recipients[0]['id'] == $_user['user_id'] xor $thisIsJustUpload) {
                    return get_lang('MailingJustUploadSelectNoOther');
                }
                $dropbox_filename = $w->filename;
                $found = true;
                // note: do we still need this?
                break;
            }
        }
    } else {
        // rename file to login_filename_uniqueId format
//.........这里部分代码省略.........
开发者ID:annickvdp,项目名称:Chamilo1.9.10,代码行数:101,代码来源:dropbox_functions.inc.php

示例8: edit_forum_attachment_file

/**
 * This function edits an attachment file into a forum
 * @param string $file_comment  a comment about file
 * @param int $post_id
 * @param int $id_attach attachment file Id
 * @return void
 */
function edit_forum_attachment_file($file_comment, $post_id, $id_attach)
{
    $_course = api_get_course_info();
    $table_forum_attachment = Database::get_course_table(TABLE_FORUM_ATTACHMENT);
    $course_id = api_get_course_int_id();
    $fileCount = count($_FILES['user_upload']['name']);
    $filesData = [];
    if (!is_array($_FILES['user_upload']['name'])) {
        $filesData[] = $_FILES['user_upload'];
    } else {
        $fileKeys = array_keys($_FILES['user_upload']);
        for ($i = 0; $i < $fileCount; $i++) {
            foreach ($fileKeys as $key) {
                $filesData[$i][$key] = $_FILES['user_upload'][$key][$i];
            }
        }
    }
    foreach ($filesData as $attachment) {
        if (empty($attachment['name'])) {
            continue;
        }
        $upload_ok = process_uploaded_file($attachment);
        if (!$upload_ok) {
            continue;
        }
        $course_dir = $_course['path'] . '/upload/forum';
        $sys_course_path = api_get_path(SYS_COURSE_PATH);
        $updir = $sys_course_path . $course_dir;
        // Try to add an extension to the file if it hasn't one.
        $new_file_name = add_ext_on_mime(stripslashes($attachment['name']), $attachment['type']);
        // User's file name
        $file_name = $attachment['name'];
        if (!filter_extension($new_file_name)) {
            Display::display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
        } else {
            $new_file_name = uniqid('');
            $new_path = $updir . '/' . $new_file_name;
            $result = @move_uploaded_file($attachment['tmp_name'], $new_path);
            $safe_file_comment = Database::escape_string($file_comment);
            $safe_file_name = Database::escape_string($file_name);
            $safe_new_file_name = Database::escape_string($new_file_name);
            $safe_post_id = (int) $post_id;
            $safe_id_attach = (int) $id_attach;
            // Storing the attachments if any.
            if ($result) {
                $sql = "UPDATE {$table_forum_attachment} SET filename = '{$safe_file_name}', comment = '{$safe_file_comment}', path = '{$safe_new_file_name}', post_id = '{$safe_post_id}', size ='" . $attachment['size'] . "'\n                       WHERE c_id = {$course_id} AND id = '{$safe_id_attach}'";
                Database::query($sql);
                api_item_property_update($_course, TOOL_FORUM_ATTACH, $safe_id_attach, 'ForumAttachmentUpdated', api_get_user_id());
            }
        }
    }
}
开发者ID:feroli1000,项目名称:chamilo-lms,代码行数:59,代码来源:forumfunction.inc.php

示例9: get_lang

 if (!$error) {
     $dropbox_filename = $_FILES['file']['name'];
     $dropbox_filesize = $_FILES['file']['size'];
     $dropbox_filetype = $_FILES['file']['type'];
     $dropbox_filetmpname = $_FILES['file']['tmp_name'];
     if ($dropbox_filesize <= 0 || $dropbox_filesize > dropbox_cnf('maxFilesize')) {
         $errormsg = get_lang('TooBig');
         // TODO: The "too big" message does not fit in the case of uploading zero-sized file.
         $error = true;
     } elseif (!is_uploaded_file($dropbox_filetmpname)) {
         // check user fraud : no clean error msg.
         die(get_lang('BadFormData') . ' (code 403)');
     }
     if (!$error) {
         // Try to add an extension to the file if it hasn't got one
         $dropbox_filename = add_ext_on_mime($dropbox_filename, $dropbox_filetype);
         // Replace dangerous characters
         $dropbox_filename = api_replace_dangerous_char($dropbox_filename);
         // Transform any .php file in .phps fo security
         $dropbox_filename = php2phps($dropbox_filename);
         if (!filter_extension($dropbox_filename)) {
             $error = true;
             $errormsg = get_lang('UplUnableToSaveFileFilteredExtension');
         } else {
             // set title
             $dropbox_title = $dropbox_filename;
             // set author
             if ($_POST['authors'] == '') {
                 $_POST['authors'] = getUserNameFromId($_user['user_id']);
             }
             if ($dropbox_overwrite) {
开发者ID:jloguercio,项目名称:chamilo-lms,代码行数:31,代码来源:dropbox_submit.php

示例10: edit_announcement_attachment_file

 /**
  * This function edit a attachment file into announcement
  * @param int attach id
  * @param array uploaded file $_FILES
  * @param string file comment
  * @return int
  */
 public static function edit_announcement_attachment_file($id_attach, $file, $file_comment)
 {
     $_course = api_get_course_info();
     $tbl_announcement_attachment = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
     $return = 0;
     $course_id = api_get_course_int_id();
     if (is_array($file) && $file['error'] == 0) {
         // TODO: This path is obsolete. The new document repository scheme should be kept in mind here.
         $courseDir = $_course['path'] . '/upload/announcements';
         $sys_course_path = api_get_path(SYS_COURSE_PATH);
         $updir = $sys_course_path . $courseDir;
         // Try to add an extension to the file if it hasn't one
         $new_file_name = add_ext_on_mime(stripslashes($file['name']), $file['type']);
         // user's file name
         $file_name = $file['name'];
         if (!filter_extension($new_file_name)) {
             $return - 1;
             Display::display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
         } else {
             $new_file_name = uniqid('');
             $new_path = $updir . '/' . $new_file_name;
             @move_uploaded_file($file['tmp_name'], $new_path);
             $safe_file_comment = Database::escape_string($file_comment);
             $safe_file_name = Database::escape_string($file_name);
             $safe_new_file_name = Database::escape_string($new_file_name);
             $id_attach = intval($id_attach);
             $sql = "UPDATE {$tbl_announcement_attachment} SET filename = '{$safe_file_name}', comment = '{$safe_file_comment}', path = '{$safe_new_file_name}', size ='" . intval($file['size']) . "'\n\t\t\t\t\t \tWHERE c_id = {$course_id} AND id = '{$id_attach}'";
             $result = Database::query($sql);
             if ($result === false) {
                 $return = -1;
                 Display::display_error_message(get_lang('UplUnableToSaveFile'));
             } else {
                 $return = 1;
             }
         }
     }
     return $return;
 }
开发者ID:secuencia24,项目名称:chamilo-lms,代码行数:45,代码来源:AnnouncementManager.php

示例11: upload_image

 /**
  * Uploads an author image to the upload/learning_path/images directory
  * @param	array	The image array, coming from the $_FILES superglobal
  * @return	boolean	True on success, false on error
  */
 public function upload_image($image_array)
 {
     $image_moved = false;
     if (!empty($image_array['name'])) {
         $upload_ok = process_uploaded_file($image_array);
         $has_attachment = true;
     } else {
         $image_moved = true;
     }
     if ($upload_ok) {
         if ($has_attachment) {
             $courseDir = api_get_course_path() . '/upload/learning_path/images';
             $sys_course_path = api_get_path(SYS_COURSE_PATH);
             $updir = $sys_course_path . $courseDir;
             // Try to add an extension to the file if it hasn't one.
             $new_file_name = add_ext_on_mime(stripslashes($image_array['name']), $image_array['type']);
             if (!filter_extension($new_file_name)) {
                 //Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
                 $image_moved = false;
             } else {
                 $file_extension = explode('.', $image_array['name']);
                 $file_extension = strtolower($file_extension[sizeof($file_extension) - 1]);
                 $filename = uniqid('');
                 $new_file_name = $filename . '.' . $file_extension;
                 $new_path = $updir . '/' . $new_file_name;
                 // Resize the image.
                 $temp = new Image($image_array['tmp_name']);
                 $picture_infos = $temp->get_image_info();
                 if ($picture_infos['width'] > 104) {
                     $thumbwidth = 104;
                 } else {
                     $thumbwidth = $picture_infos['width'];
                 }
                 if ($picture_infos['height'] > 96) {
                     $new_height = 96;
                 } else {
                     $new_height = $picture_infos['height'];
                 }
                 $temp->resize($thumbwidth, $new_height, 0);
                 $result = $temp->send_image($new_path);
                 // Storing the image filename.
                 if ($result) {
                     $image_moved = true;
                     $this->set_preview_image($new_file_name);
                     //Resize to 64px to use on course homepage
                     $temp->resize(64, 64, 0);
                     $temp->send_image($updir . '/' . $filename . '.64.' . $file_extension);
                     return true;
                 }
             }
         }
     }
     return false;
 }
开发者ID:secuencia24,项目名称:chamilo-lms,代码行数:59,代码来源:learnpath.class.php

示例12: add_edit_template

/**
 * Add (or edit) a template. This function displays the form and also takes care of uploading the image and storing the information in the database
 *
 * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
 * @version August 2008
 * @since Dokeos 1.8.6
 */
function add_edit_template()
{
    // initiate the object
    $form = new FormValidator('template', 'post', 'settings.php?category=Templates&action=' . $_GET['action'] . '&id=' . $_GET['id']);
    // settting the form elements: the header
    if ($_GET['action'] == 'add') {
        $title = get_lang('AddTemplate');
    } else {
        $title = get_lang('EditTemplate');
    }
    $form->addElement('header', '', $title);
    // settting the form elements: the title of the template
    $form->add_textfield('title', get_lang('Title'), false);
    // settting the form elements: the content of the template (wysiwyg editor)
    $form->addElement('html_editor', 'template_text', get_lang('Text'));
    // settting the form elements: the form to upload an image to be used with the template
    $form->addElement('file', 'template_image', get_lang('Image'), '');
    // settting the form elements: a little bit information about the template image
    $form->addElement('static', 'file_comment', '', get_lang('TemplateImageComment100x70'));
    // getting all the information of the template when editing a template
    if ($_GET['action'] == 'edit') {
        // Database table definition
        $table_system_template = Database::get_main_table('system_template');
        $sql = "SELECT * FROM {$table_system_template} WHERE id = '" . Database::escape_string($_GET['id']) . "'";
        $result = api_sql_query($sql, __FILE__, __LINE__);
        $row = Database::fetch_array($result);
        $defaults['template_id'] = $_GET['id'];
        $defaults['template_text'] = $row['content'];
        $defaults['title'] = $row['title'];
        // adding an extra field: a hidden field with the id of the template we are editing
        $form->addElement('hidden', 'template_id');
        // adding an extrra field: a preview of the image that is currently used
        if (!empty($row['image'])) {
            $form->addElement('static', 'template_image_preview', '', '<img src="' . api_get_path(WEB_PATH) . 'home/default_platform_document/' . $row['image'] . '" alt="' . get_lang('TemplatePreview') . '"/>');
        } else {
            $form->addElement('static', 'template_image_preview', '', '<img src="' . api_get_path(WEB_PATH) . 'home/default_platform_document/noimage.gif" alt="' . get_lang('NoTemplatePreview') . '"/>');
        }
        // setting the information of the template that we are editing
        $form->setDefaults($defaults);
    }
    // settting the form elements: the submit button
    $form->addElement('style_submit_button', 'submit', get_lang('Ok'), 'class="save"');
    // setting the rules: the required fields
    $form->addRule('title', '<div class="required">' . get_lang('ThisFieldIsRequired'), 'required');
    $form->addRule('template_text', '<div class="required">' . get_lang('ThisFieldIsRequired'), 'required');
    // if the form validates (complies to all rules) we save the information, else we display the form again (with error message if needed)
    if ($form->validate()) {
        // exporting the values
        $values = $form->exportValues();
        // upload the file
        if (!empty($_FILES['template_image']['name'])) {
            include_once api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php';
            $upload_ok = process_uploaded_file($_FILES['template_image']);
            if ($upload_ok) {
                // Try to add an extension to the file if it hasn't one
                $new_file_name = add_ext_on_mime(stripslashes($_FILES['template_image']['name']), $_FILES['template_image']['type']);
                // upload dir
                $upload_dir = api_get_path(SYS_PATH) . 'home/default_platform_document/';
                // create dir if not exists
                if (!is_dir($upload_dir)) {
                    $perm = api_get_setting('permissions_for_new_directories');
                    $perm = octdec(!empty($perm) ? $perm : '0770');
                    $res = @mkdir($upload_dir, $perm);
                }
                // resize image to max default and upload
                require_once api_get_path(LIBRARY_PATH) . 'image.lib.php';
                $temp = new image($_FILES['template_image']['tmp_name']);
                $picture_infos = @getimagesize($_FILES['template_image']['tmp_name']);
                $max_width_for_picture = 100;
                if ($picture_infos[0] > $max_width_for_picture) {
                    $thumbwidth = $max_width_for_picture;
                    if (empty($thumbwidth) or $thumbwidth == 0) {
                        $thumbwidth = $max_width_for_picture;
                    }
                    $new_height = round($thumbwidth / $picture_infos[0] * $picture_infos[1]);
                    $temp->resize($thumbwidth, $new_height, 0);
                }
                $type = $picture_infos[2];
                switch (!empty($type)) {
                    case 2:
                        $temp->send_image('JPG', $upload_dir . $new_file_name);
                        break;
                    case 3:
                        $temp->send_image('PNG', $upload_dir . $new_file_name);
                        break;
                    case 1:
                        $temp->send_image('GIF', $upload_dir . $new_file_name);
                        break;
                }
            }
        }
        // store the information in the database (as insert or as update)
        $table_system_template = Database::get_main_table('system_template');
//.........这里部分代码省略.........
开发者ID:RusticiSoftware,项目名称:SCORMCloud_DokeosMod,代码行数:101,代码来源:settings.php

示例13: edit_agenda_attachment_file

/**
 * This function edit a attachment file into agenda
 * @param string  a comment about file
 * @param int Agenda Id
 *  @param int attachment file Id
 */
function edit_agenda_attachment_file($file_comment, $agenda_id, $id_attach)
{
    global $_course;
    $agenda_table_attachment = Database::get_course_table(TABLE_AGENDA_ATTACHMENT);
    // Storing the attachments
    if (!empty($_FILES['user_upload']['name'])) {
        $upload_ok = process_uploaded_file($_FILES['user_upload']);
    }
    if (!empty($upload_ok)) {
        $courseDir = $_course['path'] . '/upload/calendar';
        $sys_course_path = api_get_path(SYS_COURSE_PATH);
        $updir = $sys_course_path . $courseDir;
        // Try to add an extension to the file if it hasn't one
        $new_file_name = add_ext_on_mime(stripslashes($_FILES['user_upload']['name']), $_FILES['user_upload']['type']);
        // user's file name
        $file_name = $_FILES['user_upload']['name'];
        if (!filter_extension($new_file_name)) {
            Display::display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
        } else {
            $new_file_name = uniqid('');
            $new_path = $updir . '/' . $new_file_name;
            $result = @move_uploaded_file($_FILES['user_upload']['tmp_name'], $new_path);
            $safe_file_comment = Database::escape_string($file_comment);
            $safe_file_name = Database::escape_string($file_name);
            $safe_new_file_name = Database::escape_string($new_file_name);
            $safe_agenda_id = intval($agenda_id);
            $safe_id_attach = intval($id_attach);
            // Storing the attachments if any
            if ($result) {
                $sql = "UPDATE {$agenda_table_attachment} SET filename = '{$safe_file_name}', comment = '{$safe_file_comment}', path = '{$safe_new_file_name}', agenda_id = '{$safe_agenda_id}', size ='" . intval($_FILES['user_upload']['size']) . "'\n\t\t\t\t\t\t   WHERE id = '{$safe_id_attach}'";
                Database::query($sql);
                api_item_property_update($_course, 'calendar_event_attachment', $safe_id_attach, 'AgendaAttachmentUpdated', api_get_user_id());
            }
        }
    }
}
开发者ID:annickvdp,项目名称:Chamilo1.9.10,代码行数:42,代码来源:agenda.inc.php

示例14: save_message_attachment_file

 /**
  * Attachment files when a message is sent
  * @param $file_attach
  * @param $ticket_id
  * @param $message_id
  * @param $message_attch_id
  * @return array
  */
 public static function save_message_attachment_file(
     $file_attach,
     $ticket_id,
     $message_id,
     $message_attch_id
 ) {
     $now = api_get_utc_datetime();
     $user_id = api_get_user_id();
     $ticket_id = intval($ticket_id);
     $new_file_name = add_ext_on_mime(
             stripslashes($file_attach['name']), $file_attach['type']
     );
     $file_name = $file_attach['name'];
     $table_support_message_attachments = Database::get_main_table(TABLE_TICKET_MESSAGE_ATTACHMENTS);
     if (!filter_extension($new_file_name)) {
         Display :: display_error_message(
             get_lang('UplUnableToSaveFileFilteredExtension')
         );
     } else {
         $new_file_name = uniqid('');
         $path_attachment = api_get_path(SYS_ARCHIVE_PATH);
         $path_message_attach = $path_attachment . 'plugin_ticket_messageattch/';
         if (!file_exists($path_message_attach)) {
             @mkdir($path_message_attach, api_get_permissions_for_new_directories(), true);
         }
         $new_path = $path_message_attach . $new_file_name;
         if (is_uploaded_file($file_attach['tmp_name'])) {
             $result = @copy($file_attach['tmp_name'], $new_path);
         }
         $safe_file_name = Database::escape_string($file_name);
         $safe_new_file_name = Database::escape_string($new_file_name);
         $sql = "INSERT INTO $table_support_message_attachments (
                 filename,
                 path,
                 ticket_id,
                 message_id,
                 message_attch_id,
                 size,
                 sys_insert_user_id,
                 sys_insert_datetime,
                 sys_lastedit_user_id,
                 sys_lastedit_datetime
             ) VALUES (
                 '$safe_file_name',
                 '$safe_new_file_name',
                 '$ticket_id',
                 '$message_id',
                 '$message_attch_id',
                 '" . $file_attach['size'] . "',
                 '$user_id',
                 '$now',
                 '$user_id',
                 '$now'
             )";
         Database::query($sql);
         return array(
             'path' => $path_message_attach . $safe_new_file_name,
             'filename' => $safe_file_name
         );
     }
 }
开发者ID:annickvdp,项目名称:Chamilo1.9.10,代码行数:69,代码来源:ticket.class.php

示例15: upload_file

 /**
  * Uploads the nanogong wav file
  * @param bool
  */
 public function upload_file($is_nano = false)
 {
     if (!empty($_FILES)) {
         $upload_ok = process_uploaded_file($_FILES['file'], false);
         if (!is_uploaded_file($_FILES['file']['tmp_name'])) {
             return 0;
         }
         if ($upload_ok) {
             // Check if there is enough space to save the file
             if (!DocumentManager::enough_space($_FILES['file']['size'], DocumentManager::get_course_quota())) {
                 return 0;
             }
             //first we delete everything before uploading the file
             $this->delete_files();
             //Reload the filename variable
             $file_name = add_ext_on_mime($_FILES['file']['name'], $_FILES['file']['type']);
             $file_name = strtolower($file_name);
             $file_info = pathinfo($file_name);
             if ($is_nano == true) {
                 $file_info['extension'] = 'wav';
             }
             $file_name = $this->filename . '.' . $file_info['extension'];
             if (in_array($file_info['extension'], $this->available_extensions)) {
                 if (move_uploaded_file($_FILES['file']['tmp_name'], $this->store_path . $file_name)) {
                     $this->store_filename = $this->store_path . $file_name;
                     return 1;
                 }
             }
         }
     }
     return 0;
 }
开发者ID:KRCM13,项目名称:chamilo-lms,代码行数:36,代码来源:nanogong.lib.php


注:本文中的add_ext_on_mime函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。