本文整理汇总了PHP中make_temp_directory函数的典型用法代码示例。如果您正苦于以下问题:PHP make_temp_directory函数的具体用法?PHP make_temp_directory怎么用?PHP make_temp_directory使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了make_temp_directory函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: close
function close()
{
global $CFG;
require_once $CFG->libdir . '/filelib.php';
$dir = 'ods/' . time();
make_temp_directory($dir);
make_temp_directory($dir . '/META-INF');
$dir = "{$CFG->tempdir}/{$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');
}
示例2: typo3
/**
* Return t3lib helper class
* @return t3lib_cs
*/
protected static function typo3()
{
static $typo3cs = null;
if (isset($typo3cs)) {
return $typo3cs;
}
global $CFG;
// Required files
require_once $CFG->libdir . '/typo3/class.t3lib_cs.php';
require_once $CFG->libdir . '/typo3/class.t3lib_div.php';
// do not use mbstring or recode because it may return invalid results in some corner cases
$GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_convMethod'] = 'iconv';
$GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] = 'iconv';
// 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_temp_directory('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 because 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->tempdir . '/'));
define('TYPO3_OS', stristr(PHP_OS, 'win') && !stristr(PHP_OS, 'darwin') ? 'WIN' : '');
$typo3cs = new t3lib_cs();
return $typo3cs;
}
示例3: 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->tempdir . "/latex";
make_temp_directory('latex');
}
示例4: get_plugintype_location
public function get_plugintype_location($plugintype)
{
$testableroot = make_temp_directory('testable_core_update_validator/plugintypes');
if (!file_exists($testableroot . '/' . $plugintype)) {
make_temp_directory('testable_core_update_validator/plugintypes/' . $plugintype);
}
return $testableroot . '/' . $plugintype;
}
示例5: setUp
public function setUp()
{
parent::setUp();
$this->resetAfterTest(true);
if (!($this->tempdir = make_temp_directory('assignfeedback_pdf'))) {
throw new coding_exception("Unable to create temporary directory");
}
}
示例6: __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();
}
示例7: set_temp_file_path
/**
* Set the file path to the temporary file.
*/
protected function set_temp_file_path()
{
global $USER, $CFG;
make_temp_directory('ratingallocate/' . $USER->id);
$path = $CFG->tempdir . '/ratingallocate/' . $USER->id . '/' . $this->filename;
// Check to see if the file exists, if so delete it.
if (file_exists($path)) {
unlink($path);
}
$this->path = $path;
}
示例8: get_google_client
/**
* Wrapper to get a Google Client object.
*
* This automatically sets the config to Moodle's defaults.
*
* @return Google_Client
*/
function get_google_client()
{
global $CFG, $SITE;
make_temp_directory('googleapi');
$tempdir = $CFG->tempdir . '/googleapi';
$config = new Google_Config();
$config->setApplicationName('Moodle ' . $CFG->release);
$config->setIoClass('moodle_google_curlio');
$config->setClassConfig('Google_Cache_File', 'directory', $tempdir);
$config->setClassConfig('Google_Auth_OAuth2', 'access_type', 'online');
$config->setClassConfig('Google_Auth_OAuth2', 'approval_prompt', 'auto');
return new Google_Client($config);
}
示例9: 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_temp_directory('excel');
$this->pear_excel_workbook->setTempDir($CFG->tempdir . '/excel');
}
示例10: 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_temp_directory('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->tempdir . '/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 = context_user::instance($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->tempdir . '/backup/' . $filename . ".mbz");
}
$filenames = array();
$filenames['privatefile'] = $record->filename;
$filenames['tmpfile'] = $filename;
return $filenames;
}
示例11: __construct
/**
* Instantiate the class instance
*
* @param string $dirroot full path to the moodle app directory root
* @param string $temproot full path to our temp directory
*/
public function __construct($dirroot = null, $temproot = null)
{
global $CFG;
if (empty($dirroot)) {
$dirroot = $CFG->dirroot;
}
if (empty($temproot)) {
// Note we are using core_plugin here as that is the valid core
// subsystem we are part of. The namespace of this class (core\update)
// does not match it for legacy reasons. The data stored in the
// temp directory are expected to survive multiple requests and
// purging caches during the upgrade, so we make use of
// make_temp_directory(). The contents of it can be removed if needed,
// given the site is in the maintenance mode (so that cron is not
// executed) and the site is not being upgraded.
$temproot = make_temp_directory('core_plugin/code_manager');
}
$this->dirroot = $dirroot;
$this->temproot = $temproot;
$this->init_temp_directories();
}
示例12: i_follow_the_emergency_download_link
/**
* On the attempt page, simulate clicking the download link to get the responses.
* @When /^I follow the emergency download link$/
*/
public function i_follow_the_emergency_download_link()
{
$session = $this->getSession();
$session->evaluateScript('
window.behat_quizaccess_offlinemode_click_handler = function(e) {
e.preventDefault();
};
document.body.addEventListener("click", window.behat_quizaccess_offlinemode_click_handler);');
$linknode = $this->find_link(get_string('savetheresponses', 'quizaccess_offlinemode'));
$this->ensure_node_is_visible($linknode);
$linknode->click();
$session->evaluateScript('
document.body.removeEventListener("click", window.behat_quizaccess_offlinemode_click_handler);');
// Get the link again, or we won't seen the new URL.
$linknode = $this->find_link(get_string('savetheresponses', 'quizaccess_offlinemode'));
$url = $linknode->getAttribute('href');
if (substr($url, 0, 30) !== 'data:application/octet-stream,') {
throw new ExpectationException('Expected the URL to look like a data URL, but it didn\'t.', $session);
}
$tempdir = make_temp_directory('behat_quizaccess_offlinemode');
$this->downloadedfile = tempnam($tempdir, 'download');
file_put_contents($this->downloadedfile, substr($url, 30));
}
示例13: scorm_debug_log_write
/**
* writes log output to a temp log file
*
* @param string $type - type of log(aicc,scorm12,scorm13) used as prefix for filename
* @param string $text - text to be written to file.
* @param integer $scoid - scoid of object this log entry is for.
*/
function scorm_debug_log_write($type, $text, $scoid) {
global $CFG;
$debugenablelog = get_config('scorm', 'allowapidebug');
if (!$debugenablelog || empty($text)) {
return;
}
if (make_temp_directory('scormlogs/')) {
$logfile = scorm_debug_log_filename($type, $scoid);
@file_put_contents($logfile, date('Y/m/d H:i:s O')." DEBUG $text\r\n", FILE_APPEND);
@chmod($logfile, $CFG->filepermissions);
}
}
示例14: generate_feedback_document
/**
* This function takes the combined pdf and embeds all the comments and annotations.
* @param int|\assign $assignment
* @param int $userid
* @param int $attemptnumber (-1 means latest attempt)
* @return stored_file
*/
public static function generate_feedback_document($assignment, $userid, $attemptnumber)
{
$assignment = self::get_assignment_from_param($assignment);
if (!$assignment->can_view_submission($userid)) {
\print_error('nopermission');
}
if (!$assignment->can_grade()) {
\print_error('nopermission');
}
// Need to generate the page images - first get a combined pdf.
$file = self::get_combined_pdf_for_attempt($assignment, $userid, $attemptnumber);
if (!$file) {
throw new \moodle_exception('Could not generate combined pdf.');
}
$tmpdir = \make_temp_directory('assignfeedback_editpdf/final/' . self::hash($assignment, $userid, $attemptnumber));
$combined = $tmpdir . '/' . self::COMBINED_PDF_FILENAME;
$file->copy_content_to($combined);
// Copy the file.
$pdf = new pdf();
$fs = \get_file_storage();
$stamptmpdir = \make_temp_directory('assignfeedback_editpdf/stamps/' . self::hash($assignment, $userid, $attemptnumber));
$grade = $assignment->get_user_grade($userid, true, $attemptnumber);
// Copy any new stamps to this instance.
if ($files = $fs->get_area_files($assignment->get_context()->id, 'assignfeedback_editpdf', 'stamps', $grade->id, "filename", false)) {
foreach ($files as $file) {
$filename = $stamptmpdir . '/' . $file->get_filename();
$file->copy_content_to($filename);
// Copy the file.
}
}
$pagecount = $pdf->set_pdf($combined);
$grade = $assignment->get_user_grade($userid, true, $attemptnumber);
page_editor::release_drafts($grade->id);
for ($i = 0; $i < $pagecount; $i++) {
$pdf->copy_page();
$comments = page_editor::get_comments($grade->id, $i, false);
$annotations = page_editor::get_annotations($grade->id, $i, false);
foreach ($comments as $comment) {
$pdf->add_comment($comment->rawtext, $comment->x, $comment->y, $comment->width, $comment->colour);
}
foreach ($annotations as $annotation) {
$pdf->add_annotation($annotation->x, $annotation->y, $annotation->endx, $annotation->endy, $annotation->colour, $annotation->type, $annotation->path, $stamptmpdir);
}
}
fulldelete($stamptmpdir);
$filename = self::get_downloadable_feedback_filename($assignment, $userid, $attemptnumber);
$filename = clean_param($filename, PARAM_FILE);
$generatedpdf = $tmpdir . '/' . $filename;
$pdf->save_pdf($generatedpdf);
$record = new \stdClass();
$record->contextid = $assignment->get_context()->id;
$record->component = 'assignfeedback_editpdf';
$record->filearea = self::FINAL_PDF_FILEAREA;
$record->itemid = $grade->id;
$record->filepath = '/';
$record->filename = $filename;
// Only keep one current version of the generated pdf.
$fs->delete_area_files($record->contextid, $record->component, $record->filearea, $record->itemid);
$file = $fs->create_file_from_pathname($record, $generatedpdf);
// Cleanup.
@unlink($generatedpdf);
@unlink($combined);
@rmdir($tmpdir);
return $file;
}
示例15: install_core
/**
* Install core moodle tables and initialize
* @param float $version target version
* @param bool $verbose
* @return void, may throw exception
*/
function install_core($version, $verbose) {
global $CFG, $DB;
// We can not call purge_all_caches() yet, make sure the temp and cache dirs exist and are empty.
remove_dir($CFG->cachedir.'', true);
make_cache_directory('', true);
remove_dir($CFG->localcachedir.'', true);
make_localcache_directory('', true);
remove_dir($CFG->tempdir.'', true);
make_temp_directory('', true);
remove_dir($CFG->dataroot.'/muc', true);
make_writable_directory($CFG->dataroot.'/muc', true);
try {
core_php_time_limit::raise(600);
print_upgrade_part_start('moodle', true, $verbose); // does not store upgrade running flag
$DB->get_manager()->install_from_xmldb_file("$CFG->libdir/db/install.xml");
upgrade_started(); // we want the flag to be stored in config table ;-)
// set all core default records and default settings
require_once("$CFG->libdir/db/install.php");
xmldb_main_install(); // installs the capabilities too
// store version
upgrade_main_savepoint(true, $version, false);
// Continue with the installation
log_update_descriptions('moodle');
external_update_descriptions('moodle');
events_update_definition('moodle');
\core\task\manager::reset_scheduled_tasks_for_component('moodle');
message_update_providers('moodle');
\core\message\inbound\manager::update_handlers_for_component('moodle');
// Write default settings unconditionally
admin_apply_default_settings(NULL, true);
print_upgrade_part_end(null, true, $verbose);
// Purge all caches. They're disabled but this ensures that we don't have any persistent data just in case something
// during installation didn't use APIs.
cache_helper::purge_all();
} catch (exception $ex) {
upgrade_handle_exception($ex);
}
}