本文整理汇总了PHP中make_upload_directory函数的典型用法代码示例。如果您正苦于以下问题:PHP make_upload_directory函数的具体用法?PHP make_upload_directory怎么用?PHP make_upload_directory使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了make_upload_directory函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: latex
/**
* Constructor - create temporary directories and build paths to
* external 'helper' binaries.
* Other platforms could/should be added
*/
function latex()
{
global $CFG;
// construct directory structure
$this->temp_dir = $CFG->dataroot . "/temp/latex";
make_upload_directory('temp/latex');
}
开发者ID:vuchannguyen,项目名称:web,代码行数:12,代码来源:latex.php
示例2: webquest_upgrade
function webquest_upgrade($oldversion)
{
/// This function does anything necessary to upgrade
/// older versions to match current functionality
$status = true;
global $CFG;
if ($oldversion < 2007081222) {
require_once $CFG->dirroot . '/backup/lib.php';
//make the change into each course
$courses = get_records("course");
foreach ($courses as $course) {
$newdir = "{$course->id}/{$CFG->moddata}/webquest";
if (make_upload_directory($newdir)) {
$olddir = "{$CFG->dataroot}/{$course->id}/{$CFG->moddata}/webquest/submissions";
//chec k if the old directory exists
if (is_dir($olddir)) {
$status = backup_copy_file($olddir, $CFG->dataroot . "/" . $newdir);
}
if ($status) {
fulldelete($olddir);
}
}
}
}
return $status;
}
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:26,代码来源:mysql.php
示例3: close
function close()
{
global $CFG;
require_once $CFG->libdir . '/filelib.php';
$dir = 'temp/ods/' . time();
make_upload_directory($dir);
make_upload_directory($dir . '/META-INF');
$dir = "{$CFG->dataroot}/{$dir}";
$files = array();
$handle = fopen("{$dir}/mimetype", 'w');
fwrite($handle, get_ods_mimetype());
$files[] = "{$dir}/mimetype";
$handle = fopen("{$dir}/content.xml", 'w');
fwrite($handle, get_ods_content($this->worksheets));
$files[] = "{$dir}/content.xml";
$handle = fopen("{$dir}/meta.xml", 'w');
fwrite($handle, get_ods_meta());
$files[] = "{$dir}/meta.xml";
$handle = fopen("{$dir}/styles.xml", 'w');
fwrite($handle, get_ods_styles());
$files[] = "{$dir}/styles.xml";
$handle = fopen("{$dir}/META-INF/manifest.xml", 'w');
fwrite($handle, get_ods_manifest());
$files[] = "{$dir}/META-INF";
$filename = "{$dir}/result.ods";
zip_files($files, $filename);
$handle = fopen($filename, 'rb');
$contents = fread($handle, filesize($filename));
fclose($handle);
remove_dir($dir);
// cleanup the temp directory
send_file($contents, $this->filename, 0, 0, true, true, 'application/vnd.oasis.opendocument.spreadsheet');
}
开发者ID:vuchannguyen,项目名称:web,代码行数:33,代码来源:odslib.class.php
示例4: __construct
public function __construct()
{
global $CFG;
make_upload_directory('upgradelogs');
$date = date('Ymd-His');
$this->handle = fopen($CFG->dataroot . '/upgradelogs/qe_' . $date . '.html', 'a');
fwrite($this->handle, '<html><head><title>Question engine upgrade assumptions ' . $date . '</title></head><body><h2>Question engine upgrade assumptions ' . $date . "</h2>\n\n");
}
开发者ID:evltuma,项目名称:moodle,代码行数:8,代码来源:logger.php
示例5: __construct
/**
* Constructor.
*/
public function __construct()
{
make_temp_directory('');
make_upload_directory('lang');
$this->info = array();
$this->errors = array();
$this->installer = new \lang_installer();
$this->availablelangs = $this->installer->get_remote_list_of_languages();
}
开发者ID:EsdrasCaleb,项目名称:moodle,代码行数:12,代码来源:controller.php
示例6: textlib_get_instance
/**
* As we implement the singleton pattern to use this class (only one instance
* is shared globally), we need this helper function
*
* IMPORTANT Note: Typo3 libraries always expect lowercase charsets to use 100%
* its capabilities so, don't forget to make the conversion
* from every wrapper function!
*
* @return textlib singleton instance of textlib
*/
function textlib_get_instance()
{
global $CFG;
static $instance = null;
if (!$instance) {
/// initialisation is delayed because we do not want this on each page ;-)
/// Required files
require_once $CFG->libdir . '/typo3/class.t3lib_cs.php';
require_once $CFG->libdir . '/typo3/class.t3lib_div.php';
/// If ICONV is available, lets Typo3 library use it for convert
if (extension_loaded('iconv')) {
$GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_convMethod'] = 'iconv';
/// Else if mbstring is available, lets Typo3 library use it
} else {
if (extension_loaded('mbstring')) {
$GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_convMethod'] = 'mbstring';
/// Else if recode is available, lets Typo3 library use it
} else {
if (extension_loaded('recode')) {
$GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_convMethod'] = 'recode';
} else {
$GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_convMethod'] = '';
}
}
}
/// If mbstring is available, lets Typo3 library use it for functions
if (extension_loaded('mbstring')) {
$GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] = 'mbstring';
} else {
$GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] = '';
}
/// Tell Typo3 we are curl enabled always (mandatory since 2.0)
$GLOBALS['TYPO3_CONF_VARS']['SYS']['curlUse'] = '1';
/// And this directory must exist to allow Typo to cache conversion
/// tables when using internal functions
make_upload_directory('temp/typo3temp/cs');
/// Make sure typo is using our dir permissions
$GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask'] = decoct($CFG->directorypermissions);
/// Default mask for Typo
$GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = $CFG->directorypermissions;
/// This full path constants must be defined too, transforming backslashes
/// to forward slashed beacuse Typo3 requires it.
define('PATH_t3lib', str_replace('\\', '/', $CFG->libdir . '/typo3/'));
define('PATH_typo3', str_replace('\\', '/', $CFG->libdir . '/typo3/'));
define('PATH_site', str_replace('\\', '/', $CFG->dataroot . '/temp/'));
define('TYPO3_OS', stristr(PHP_OS, 'win') && !stristr(PHP_OS, 'darwin') ? 'WIN' : '');
$instance = new textlib();
}
return $instance;
}
开发者ID:vuchannguyen,项目名称:web,代码行数:60,代码来源:textlib.class.php
示例7: MoodleExcelWorkbook
/**
* Constructs one Moodle Workbook.
*
* @global object
* @param string $filename The name of the file
*/
function MoodleExcelWorkbook($filename) {
global $CFG;
/// Internally, create one PEAR Spreadsheet_Excel_Writer_Workbook class
$this->pear_excel_workbook = new Spreadsheet_Excel_Writer($filename);
/// Prepare it to accept UTF-16LE data and to encode it properly
if (empty($CFG->latinexcelexport)) { /// Only if don't want to use latin (win1252) stronger output
$this->pear_excel_workbook->setVersion(8);
$this->latin_output = false;
} else { /// We want latin (win1252) output
$this->latin_output = true;
}
/// Choose our temporary directory - see MDL-7176, found by paulo.matos
make_upload_directory('temp/excel');
$this->pear_excel_workbook->setTempDir($CFG->dataroot.'/temp/excel');
}
开发者ID:nuckey,项目名称:moodle,代码行数:21,代码来源:excellib.class.php
示例8: get_course_media_files
/**
* gets a list of all the media files for the given course
*
* @param int courseid
* @return array containing filenames
* @calledfrom type/<typename>/editquestion.php
* @package questionbank
* @subpackage importexport
*/
function get_course_media_files($courseid)
{
// this code lifted from mod/quiz/question.php and modified
global $CFG;
$images = null;
make_upload_directory("{$course->id}");
// Just in case
$coursefiles = get_directory_list("{$CFG->dataroot}/{$courseid}", $CFG->moddata);
foreach ($coursefiles as $filename) {
if (is_media_by_extension($filename)) {
$images["{$filename}"] = $filename;
}
}
return $images;
}
开发者ID:edwinphillips,项目名称:moodle-485cb39,代码行数:24,代码来源:qt_common.php
示例9: moodle_binary_get_path
function moodle_binary_get_path($id, $meta, $course, $wiki, $userid, $groupid)
{
global $CFG;
$entry = wiki_get_entry($wiki, $course, $userid, $groupid);
if (!$entry) {
print_error('cannotgetentry', 'wiki');
}
$dir = make_upload_directory("{$course->id}/{$CFG->moddata}/wiki/{$wiki->id}/{$entry->id}/" . $meta["section"]);
if (substr($id, 0, strlen(EWIKI_IDF_INTERNAL)) != EWIKI_IDF_INTERNAL) {
print_error('cannotstartwith', 'wiki', '', EWIKI_IDF_INTERNAL . substr($id, 0, strlen(EWIKI_IDF_INTERNAL)));
}
$id = substr($id, strlen(EWIKI_IDF_INTERNAL));
$id = clean_filename($id);
return "{$dir}/{$id}";
}
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:15,代码来源:moodle_binary_store.php
示例10: imagegallery_process_zip_file
function imagegallery_process_zip_file($file)
{
global $CFG, $USER, $gallery;
$tmpdir = random_string(6);
$fullpath = make_upload_directory($tmpdir);
$origpath = dirname($file->path);
if (!unzip_file($file->path, $fullpath)) {
error(get_string("unzipfileserror", "error"));
}
$images = imagegallery_search_images($fullpath);
if (!empty($images)) {
foreach ($images as $image) {
$newpath = $origpath . '/' . basename($image);
// If file already exists, just skip it.
if (@file_exists($newpath)) {
continue;
}
$fileinfo = getimagesize($image);
if (!rename($image, $newpath)) {
error("Could not move file to new location!");
}
$newfile = new stdClass();
$newfile->galleryid = $file->galleryid;
$newfile->categoryid = $file->categoryid;
$newfile->userid = $USER->id;
$newfile->name = basename($image);
$newfile->path = $newpath;
$newfile->size = filesize($newpath);
$newfile->mime = mimeinfo('type', basename($image));
$newfile->width = $fileinfo[0];
$newfile->height = $fileinfo[1];
$newfile->timecreated = time();
$newfile->timemodified = time();
// Check dimensions.
$gallery->check_dimensions($newfile);
$newfile->path = $gallery->get_file_path($newpath);
if (!insert_record("imagegallery_images", $newfile)) {
@unlink($newpath);
error("Could not add new file {$file->name} to database!", "{$CFG->wwwroot}/mod/imagegallery/view.php?id={$gallery->cm->id}");
}
// Make thumbnail.
$thumb = $origpath . '/thumb_' . $newfile->name;
$gallery->make_thumbnail($newpath, $thumb);
}
}
fulldelete($fullpath);
@unlink($file->path);
}
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:48,代码来源:upload.php
示例11: setup_test_maxima_connection
/**
* Helper that sets up the maxima configuration. This allows maxima to be used
* from test classes that cannot subclass this one, for whatever reason.
*/
public static function setup_test_maxima_connection()
{
global $CFG;
if (!self::is_test_config_available()) {
throw new coding_exception('The calling code should call setup_test_maxima_connection ' . 'and skip the test in an appropriate way if it returns false.');
}
if (!defined('QTYPE_STACK_EXPECTED_VERSION')) {
if (!preg_match('~\\[ STACK-Maxima started, library version (\\d{10}) \\]~', file_get_contents($CFG->dirroot . '/question/type/stack/stack/maxima/stackmaxima.mac'), $matches)) {
throw new coding_exception('Maxima libraries version number not found in stackmaxima.mac.');
}
define('QTYPE_STACK_EXPECTED_VERSION', $matches[1]);
}
set_config('platform', QTYPE_STACK_TEST_CONFIG_PLATFORM, 'qtype_stack');
set_config('maximaversion', QTYPE_STACK_TEST_CONFIG_MAXIMAVERSION, 'qtype_stack');
set_config('castimeout', QTYPE_STACK_TEST_CONFIG_CASTIMEOUT, 'qtype_stack');
set_config('casresultscache', QTYPE_STACK_TEST_CONFIG_CASRESULTSCACHE, 'qtype_stack');
set_config('maximacommand', QTYPE_STACK_TEST_CONFIG_MAXIMACOMMAND, 'qtype_stack');
set_config('plotcommand', QTYPE_STACK_TEST_CONFIG_PLOTCOMMAND, 'qtype_stack');
set_config('casdebugging', QTYPE_STACK_TEST_CONFIG_CASDEBUGGING, 'qtype_stack');
set_config('mathsdisplay', 'mathjax', 'qtype_stack');
set_config('replacedollars', 0, 'qtype_stack');
set_config('stackmaximaversion', QTYPE_STACK_EXPECTED_VERSION, 'qtype_stack');
if (QTYPE_STACK_TEST_CONFIG_CASRESULTSCACHE == 'otherdb') {
set_config('cascachedbtype', QTYPE_STACK_TEST_CONFIG_CASCACHEDBTYPE, 'qtype_stack');
set_config('cascachedblibrary', QTYPE_STACK_TEST_CONFIG_CASCACHEDBLIBRARY, 'qtype_stack');
set_config('cascachedbhost', QTYPE_STACK_TEST_CONFIG_CASCACHEDBHOST, 'qtype_stack');
set_config('cascachedbname', QTYPE_STACK_TEST_CONFIG_CASCACHEDBNAME, 'qtype_stack');
set_config('cascachedbuser', QTYPE_STACK_TEST_CONFIG_CASCACHEDBUSER, 'qtype_stack');
set_config('cascachedbpass', QTYPE_STACK_TEST_CONFIG_CASCACHEDBPASS, 'qtype_stack');
set_config('cascachedbprefix', QTYPE_STACK_TEST_CONFIG_CASCACHEDBPREFIX, 'qtype_stack');
if (defined('QTYPE_STACK_TEST_CONFIG_CASCACHEDBSOCKET')) {
set_config('cascachedbsocket', QTYPE_STACK_TEST_CONFIG_CASCACHEDBSOCKET, 'qtype_stack');
}
}
if (defined('QTYPE_STACK_TEST_CONFIG_SERVERUSERPASS')) {
set_config('serveruserpass', QTYPE_STACK_TEST_CONFIG_SERVERUSERPASS, 'qtype_stack');
}
if (stack_cas_configuration::maxima_bat_is_missing()) {
stack_cas_configuration::create_maximalocal();
}
// Create the required directories inside moodledata.
make_upload_directory('stack');
make_upload_directory('stack/logs');
make_upload_directory('stack/plots');
make_upload_directory('stack/tmp');
}
开发者ID:profcab,项目名称:moodle-qtype_stack,代码行数:50,代码来源:test_maxima_configuration.php
示例12: outdated_langpack_is_installed
/**
* Downloads a langpack and fakes it being outdated
*
* @param string $langcode The language code (e.g. en)
* @Given /^outdated langpack \'([^\']*)\' is installed$/
*/
public function outdated_langpack_is_installed($langcode)
{
global $CFG;
require_once $CFG->libdir . '/componentlib.class.php';
// Download the langpack.
$dir = make_upload_directory('lang');
$installer = new lang_installer($langcode);
$result = $installer->run();
if ($result[$langcode] !== lang_installer::RESULT_INSTALLED) {
throw new coding_exception("Failed to install langpack '{$langcode}'");
}
$path = "{$dir}/{$langcode}/{$langcode}.md5";
if (!file_exists($path)) {
throw new coding_exception("Failed to find '{$langcode}' checksum");
}
file_put_contents($path, '000000');
}
开发者ID:evltuma,项目名称:moodle,代码行数:23,代码来源:behat_tool_langimport.php
示例13: block_community_download_course_backup
/**
* Download the community course backup and save it in file API
* @param integer $courseid
* @param string $huburl
* @return array 'privatefile' the file name saved in private area
* 'tmpfile' the file name saved in the moodledata temp dir (for restore)
*/
public function block_community_download_course_backup($course)
{
global $CFG, $USER;
require_once $CFG->libdir . "/filelib.php";
require_once $CFG->dirroot . "/course/publish/lib.php";
$params['courseid'] = $course->id;
$params['filetype'] = HUB_BACKUP_FILE_TYPE;
make_upload_directory('temp/backup');
$filename = md5(time() . '-' . $course->id . '-' . $USER->id . '-' . random_string(20));
$url = new moodle_url($course->huburl . '/local/hub/webservice/download.php', $params);
$path = $CFG->dataroot . '/temp/backup/' . $filename . ".mbz";
$fp = fopen($path, 'w');
$curlurl = $course->huburl . '/local/hub/webservice/download.php?filetype=' . HUB_BACKUP_FILE_TYPE . '&courseid=' . $course->id;
//send an identification token if the site is registered on the hub
require_once $CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php';
$registrationmanager = new registration_manager();
$registeredhub = $registrationmanager->get_registeredhub($course->huburl);
if (!empty($registeredhub)) {
$token = $registeredhub->token;
$curlurl .= '&token=' . $token;
}
$ch = curl_init($curlurl);
curl_setopt($ch, CURLOPT_FILE, $fp);
$data = curl_exec($ch);
curl_close($ch);
fclose($fp);
$fs = get_file_storage();
$record = new stdClass();
$record->contextid = get_context_instance(CONTEXT_USER, $USER->id)->id;
$record->component = 'user';
$record->filearea = 'private';
$record->itemid = 0;
$record->filename = urlencode($course->fullname) . "_" . time() . ".mbz";
$record->filepath = '/downloaded_backup/';
if (!$fs->file_exists($record->contextid, $record->component, $record->filearea, 0, $record->filepath, $record->filename)) {
$fs->create_file_from_pathname($record, $CFG->dataroot . '/temp/backup/' . $filename . ".mbz");
}
$filenames = array();
$filenames['privatefile'] = $record->filename;
$filenames['tmpfile'] = $filename;
return $filenames;
}
开发者ID:vuchannguyen,项目名称:web,代码行数:49,代码来源:locallib.php
示例14: definition
function definition()
{
global $CFG;
global $COURSE;
$mform =& $this->_form;
//-- General --------------------------------------------------------------------
$mform->addElement('header', 'general', get_string('general', 'form'));
/// name
$mform->addElement('text', 'name', get_string('name'), array('size' => '60'));
$mform->setType('name', PARAM_TEXT);
$mform->addRule('name', null, 'required', null, 'client');
/// text (description)
$mform->addElement('htmleditor', 'text', get_string('description'));
$mform->setType('text', PARAM_RAW);
//$mform->addRule('text', get_string('required'), 'required', null, 'client');
$mform->setHelpButton('text', array('writing', 'richtext'), false, 'editorhelpbutton');
/// introformat
$mform->addElement('format', 'introformat', get_string('format'));
//-- Stamp Collection------------------------------------------------------------
$mform->addElement('header', 'stampcollection', get_string('modulename', 'stampcoll'));
/// stampimage
make_upload_directory("{$COURSE->id}");
// Just in case
$images = array();
$coursefiles = get_directory_list("{$CFG->dataroot}/{$COURSE->id}", $CFG->moddata);
foreach ($coursefiles as $filename) {
if (mimeinfo("icon", $filename) == "image.gif") {
$images["{$filename}"] = $filename;
}
}
$mform->addElement('select', 'image', get_string('stampimage', 'stampcoll'), array_merge(array('' => get_string('default')), $images), 'a', 'b', 'c', 'd');
$mform->addElement('static', 'stampimageinfo', '', get_string('stampimageinfo', 'stampcoll'));
/// displayzero
$mform->addElement('selectyesno', 'displayzero', get_string('displayzero', 'stampcoll'));
$mform->setDefault('displayzero', 0);
//-------------------------------------------------------------------------------
// add standard elements, common to all modules
$this->standard_coursemodule_elements();
//-------------------------------------------------------------------------------
// add standard buttons, common to all modules
$this->add_action_buttons();
}
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:42,代码来源:mod_form.php
示例15: prepare_authorization
/**
* Generates a random token and stores it in a file in moodledata directory.
*
* @return array of the (string)filename and (string)password in this order
*/
public function prepare_authorization()
{
global $CFG;
make_upload_directory('mdeploy/auth/');
$attempts = 0;
$success = false;
while (!$success and $attempts < 5) {
$attempts++;
$passfile = $this->generate_passfile();
$password = $this->generate_password();
$now = time();
$filepath = $CFG->dataroot . '/mdeploy/auth/' . $passfile;
if (!file_exists($filepath)) {
$success = file_put_contents($filepath, $password . PHP_EOL . $now . PHP_EOL, LOCK_EX);
}
}
if ($success) {
return array($passfile, $password);
} else {
throw new moodle_exception('unable_prepare_authorization', 'core_plugin');
}
}
开发者ID:masaterutakeno,项目名称:MoodleMobile,代码行数:27,代码来源:pluginlib.php
示例16: save_files
/**
* Moves all the files to the destination directory.
*
* @uses $CFG
* @uses $USER
* @param string $destination The destination directory.
* @return boolean status;
*/
function save_files($destination)
{
global $CFG, $USER, $OUTPUT;
if (!$this->status) {
// preprocess_files hasn't been run
$this->preprocess_files();
}
// if there are no files, bail before we create an empty directory.
if (empty($this->config->somethingtosave)) {
return true;
}
$savedsomething = false;
if ($this->status) {
if (!(strpos($destination, $CFG->dataroot) === false)) {
// take it out for giving to make_upload_directory
$destination = substr($destination, strlen($CFG->dataroot) + 1);
}
if ($destination[strlen($destination) - 1] == '/') {
// strip off a trailing / if we have one
$destination = substr($destination, 0, -1);
}
if (!make_upload_directory($destination, true)) {
//TODO maybe put this function here instead of moodlelib.php now.
$this->status = false;
return false;
}
$destination = $CFG->dataroot . '/' . $destination;
// now add it back in so we have a full path
$exceptions = array();
//need this later if we're deleting other files.
foreach (array_keys($this->files) as $i) {
if (!$this->files[$i]['clear']) {
// not ok to save
continue;
}
if ($this->config->handlecollisions) {
$this->handle_filename_collision($destination, $this->files[$i]);
}
if (move_uploaded_file($this->files[$i]['tmp_name'], $destination . '/' . $this->files[$i]['name'])) {
chmod($destination . '/' . $this->files[$i]['name'], $CFG->directorypermissions);
$this->files[$i]['fullpath'] = $destination . '/' . $this->files[$i]['name'];
$this->files[$i]['uploadlog'] .= "\n" . get_string('uploadedfile');
$this->files[$i]['saved'] = true;
$exceptions[] = $this->files[$i]['name'];
// now add it to the log (this is important so we know who to notify if a virus is found later on)
clam_log_upload($this->files[$i]['fullpath'], $this->course);
$savedsomething = true;
}
}
if ($savedsomething && $this->config->deleteothers) {
$this->delete_other_files($destination, $exceptions);
}
}
if (empty($savedsomething)) {
$this->status = false;
if (empty($this->config->allownull) && !empty($this->inputname) || empty($this->inputname) && empty($this->config->allownullmultiple)) {
echo $OUTPUT->notification(get_string('uploadnofilefound'));
}
return false;
}
return $this->status;
}
开发者ID:masaterutakeno,项目名称:MoodleMobile,代码行数:70,代码来源:uploadlib.php
示例17: optional_param
<?php
// $Id: maintenance.php,v 1.12 2007/04/30 17:08:44 skodak Exp $
// Enables/disables maintenance mode
require '../config.php';
require_once $CFG->libdir . '/adminlib.php';
$action = optional_param('action', '', PARAM_ALPHA);
admin_externalpage_setup('maintenancemode');
//Check folder exists
if (!make_upload_directory(SITEID)) {
// Site folder
error("Could not create site folder. The site administrator needs to fix the file permissions");
}
$filename = $CFG->dataroot . '/' . SITEID . '/maintenance.html';
if ($form = data_submitted()) {
if (confirm_sesskey()) {
if ($form->action == "disable") {
unlink($filename);
redirect('maintenance.php', get_string('sitemaintenanceoff', 'admin'));
} else {
$file = fopen($filename, 'w');
fwrite($file, stripslashes($form->text));
fclose($file);
redirect('maintenance.php', get_string('sitemaintenanceon', 'admin'));
}
}
}
/// Print the header stuff
admin_externalpage_print_header();
/// Print the appropriate form
if (file_exists($filename)) {
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:31,代码来源:maintenance.php
示例18: is_dataroot_insecure
/**
* Try to verify that dataroot is not accessible from web.
*
* Try to verify that dataroot is not accessible from web.
* It is not 100% correct but might help to reduce number of vulnerable sites.
* Protection from httpd.conf and .htaccess is not detected properly.
*
* @uses INSECURE_DATAROOT_WARNING
* @uses INSECURE_DATAROOT_ERROR
* @param bool $fetchtest try to test public access by fetching file, default false
* @return mixed empty means secure, INSECURE_DATAROOT_ERROR found a critical problem, INSECURE_DATAROOT_WARNING might be problematic
*/
function is_dataroot_insecure($fetchtest = false)
{
global $CFG;
$siteroot = str_replace('\\', '/', strrev($CFG->dirroot . '/'));
// win32 backslash workaround
$rp = preg_replace('|https?://[^/]+|i', '', $CFG->wwwroot, 1);
$rp = strrev(trim($rp, '/'));
$rp = explode('/', $rp);
foreach ($rp as $r) {
if (strpos($siteroot, '/' . $r . '/') === 0) {
$siteroot = substr($siteroot, strlen($r) + 1);
// moodle web in subdirectory
} else {
break;
// probably alias root
}
}
$siteroot = strrev($siteroot);
$dataroot = str_replace('\\', '/', $CFG->dataroot . '/');
if (strpos($dataroot, $siteroot) !== 0) {
return false;
}
if (!$fetchtest) {
return INSECURE_DATAROOT_WARNING;
}
// now try all methods to fetch a test file using http protocol
$httpdocroot = str_replace('\\', '/', strrev($CFG->dirroot . '/'));
preg_match('|(https?://[^/]+)|i', $CFG->wwwroot, $matches);
$httpdocroot = $matches[1];
$datarooturl = $httpdocroot . '/' . substr($dataroot, strlen($siteroot));
make_upload_directory('diag');
$testfile = $CFG->dataroot . '/diag/public.txt';
if (!file_exists($testfile)) {
file_put_contents($testfile, 'test file, do not delete');
}
$teststr = trim(file_get_contents($testfile));
if (empty($teststr)) {
// hmm, strange
return INSECURE_DATAROOT_WARNING;
}
$testurl = $datarooturl . '/diag/public.txt';
if (extension_loaded('curl') and !(stripos(ini_get('disable_functions'), 'curl_init') !== FALSE) and !(stripos(ini_get('disable_functions'), 'curl_setop') !== FALSE) and ($ch = @curl_init($testurl)) !== false) {
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
$data = curl_exec($ch);
if (!curl_errno($ch)) {
$data = trim($data);
if ($data === $teststr) {
curl_close($ch);
return INSECURE_DATAROOT_ERROR;
}
}
curl_close($ch);
}
if ($data = @file_get_contents($testurl)) {
$data = trim($data);
if ($data === $teststr) {
return INSECURE_DATAROOT_ERROR;
}
}
preg_match('|https?://([^/]+)|i', $testurl, $matches);
$sitename = $matches[1];
$error = 0;
if ($fp = @fsockopen($sitename, 80, $error)) {
preg_match('|https?://[^/]+(.*)|i', $testurl, $matches);
$localurl = $matches[1];
$out = "GET {$localurl} HTTP/1.1\r\n";
$out .= "Host: {$sitename}\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
$data = '';
$incoming = false;
while (!feof($fp)) {
if ($incoming) {
$data .= fgets($fp, 1024);
} else {
if (@fgets($fp, 1024) === "\r\n") {
$incoming = true;
}
}
}
fclose($fp);
$data = trim($data);
if ($data === $teststr) {
return INSECURE_DATAROOT_ERROR;
}
}
return INSECURE_DATAROOT_WARNING;
//.........这里部分代码省略.........
开发者ID:raymondAntonio,项目名称:moodle,代码行数:101,代码来源:adminlib.php
示例19: print_footer
echo '<input type="hidden" name="action" value="save3" />';
echo '<input type="hidden" name="d" value="' . $data->id . '" />';
echo '<input type="hidden" name="sesskey" value="' . $sesskey . '" />';
echo '<input type="submit" value="' . $stroverwrite . '" /></div></form>';
echo '</div>';
print_footer($course);
exit;
break;
}
case 'save3':
if (!data_submitted() or !confirm_sesskey()) {
error("Invalid request");
}
$name = optional_param('name', $data->name, PARAM_FILE);
$presetdirectory = "/data/preset/{$USER->id}/{$name}";
make_upload_directory($presetdirectory);
clean_preset($CFG->dataroot . $presetdirectory);
$file = data_presets_export($course, $cm, $data);
if (!unzip_file($file, $CFG->dataroot . $presetdirectory, false)) {
error("Can't unzip to the preset directory");
}
notify(get_string('savesuccess', 'data'), 'notifysuccess');
break;
}
$presets = data_get_available_presets($context);
$strimport = get_string('import');
$strfromfile = get_string('fromfile', 'data');
$strchooseorupload = get_string('chooseorupload', 'data');
$strusestandard = get_string('usestandard', 'data');
$strchoose = get_string('choose');
$strexport = get_string('export', 'data');
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:31,代码来源:preset.php
示例20: file_area
/**
* Makes an upload directory
*
* @param $userid int The user id
* @return string path to file area.
*/
function file_area($userid)
{
return make_upload_directory($this->file_area_name($userid));
}
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:10,代码来源:lib.php
注:本文中的make_upload_directory函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论