本文整理汇总了PHP中stored_file::get_content方法的典型用法代码示例。如果您正苦于以下问题:PHP stored_file::get_content方法的具体用法?PHP stored_file::get_content怎么用?PHP stored_file::get_content使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stored_file
的用法示例。
在下文中一共展示了stored_file::get_content方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: scorm_parse_scorm
/**
* Sets up SCORM 1.2/2004 packages using the manifest file.
* Called whenever SCORM changes
* @param object $scorm instance - fields are updated and changes saved into database
* @param stored_file|string $manifest - path to manifest file or stored_file.
* @return bool
*/
function scorm_parse_scorm(&$scorm, $manifest)
{
global $CFG, $DB;
// load manifest into string
if ($manifest instanceof stored_file) {
$xmltext = $manifest->get_content();
} else {
require_once "{$CFG->libdir}/filelib.php";
$xmltext = download_file_content($manifest);
}
$defaultorgid = 0;
$firstinorg = 0;
$pattern = '/&(?!\\w{2,6};)/';
$replacement = '&';
$xmltext = preg_replace($pattern, $replacement, $xmltext);
$objXML = new xml2Array();
$manifests = $objXML->parse($xmltext);
$scoes = new stdClass();
$scoes->version = '';
$scoes = scorm_get_manifest($manifests, $scoes);
$newscoes = array();
$sortorder = 0;
if (count($scoes->elements) > 0) {
$olditems = $DB->get_records('scorm_scoes', array('scorm' => $scorm->id));
foreach ($scoes->elements as $manifest => $organizations) {
foreach ($organizations as $organization => $items) {
foreach ($items as $identifier => $item) {
$sortorder++;
// This new db mngt will support all SCORM future extensions
$newitem = new stdClass();
$newitem->scorm = $scorm->id;
$newitem->manifest = $manifest;
$newitem->organization = $organization;
$newitem->sortorder = $sortorder;
$standarddatas = array('parent', 'identifier', 'launch', 'scormtype', 'title');
foreach ($standarddatas as $standarddata) {
if (isset($item->{$standarddata})) {
$newitem->{$standarddata} = $item->{$standarddata};
} else {
$newitem->{$standarddata} = '';
}
}
if (!empty($defaultorgid) && !empty($scoes->defaultorg) && empty($firstinorg) && $newitem->parent == $scoes->defaultorg) {
$firstinorg = $sortorder;
}
if (!empty($olditems) && ($olditemid = scorm_array_search('identifier', $newitem->identifier, $olditems))) {
$newitem->id = $olditemid;
// Update the Sco sortorder but keep id so that user tracks are kept against the same ids.
$DB->update_record('scorm_scoes', $newitem);
$id = $olditemid;
// Remove all old data so we don't duplicate it.
$DB->delete_records('scorm_scoes_data', array('scoid' => $olditemid));
$DB->delete_records('scorm_seq_objective', array('scoid' => $olditemid));
$DB->delete_records('scorm_seq_mapinfo', array('scoid' => $olditemid));
$DB->delete_records('scorm_seq_ruleconds', array('scoid' => $olditemid));
$DB->delete_records('scorm_seq_rulecond', array('scoid' => $olditemid));
$DB->delete_records('scorm_seq_rolluprule', array('scoid' => $olditemid));
$DB->delete_records('scorm_seq_rolluprulecond', array('scoid' => $olditemid));
// Now remove this SCO from the olditems object as we have dealt with it.
unset($olditems[$olditemid]);
} else {
// Insert the new SCO, and retain the link between the old and new for later adjustment
$id = $DB->insert_record('scorm_scoes', $newitem);
}
$newscoes[$id] = $newitem;
// Save this sco in memory so we can use it later.
if ($optionaldatas = scorm_optionals_data($item, $standarddatas)) {
$data = new stdClass();
$data->scoid = $id;
foreach ($optionaldatas as $optionaldata) {
if (isset($item->{$optionaldata})) {
$data->name = $optionaldata;
$data->value = $item->{$optionaldata};
$dataid = $DB->insert_record('scorm_scoes_data', $data);
}
}
}
if (isset($item->sequencingrules)) {
foreach ($item->sequencingrules as $sequencingrule) {
$rule = new stdClass();
$rule->scoid = $id;
$rule->ruletype = $sequencingrule->type;
$rule->conditioncombination = $sequencingrule->conditioncombination;
$rule->action = $sequencingrule->action;
$ruleid = $DB->insert_record('scorm_seq_ruleconds', $rule);
if (isset($sequencingrule->ruleconditions)) {
foreach ($sequencingrule->ruleconditions as $rulecondition) {
$rulecond = new stdClass();
$rulecond->scoid = $id;
$rulecond->ruleconditionsid = $ruleid;
$rulecond->referencedobjective = $rulecondition->referencedobjective;
$rulecond->measurethreshold = $rulecondition->measurethreshold;
$rulecond->operator = $rulecondition->operator;
//.........这里部分代码省略.........
示例2: send_stored_file
//.........这里部分代码省略.........
header('Pragma: ');
if (empty($CFG->disablebyteserving) && $mimetype != 'text/plain' && $mimetype != 'text/html') {
header('Accept-Ranges: bytes');
if (!empty($_SERVER['HTTP_RANGE']) && strpos($_SERVER['HTTP_RANGE'], 'bytes=') !== FALSE) {
// byteserving stuff - for acrobat reader and download accelerators
// see: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35
// inspired by: http://www.coneural.org/florian/papers/04_byteserving.php
$ranges = false;
if (preg_match_all('/(\\d*)-(\\d*)/', $_SERVER['HTTP_RANGE'], $ranges, PREG_SET_ORDER)) {
foreach ($ranges as $key => $value) {
if ($ranges[$key][1] == '') {
//suffix case
$ranges[$key][1] = $filesize - $ranges[$key][2];
$ranges[$key][2] = $filesize - 1;
} else {
if ($ranges[$key][2] == '' || $ranges[$key][2] > $filesize - 1) {
//fix range length
$ranges[$key][2] = $filesize - 1;
}
}
if ($ranges[$key][2] != '' && $ranges[$key][2] < $ranges[$key][1]) {
//invalid byte-range ==> ignore header
$ranges = false;
break;
}
//prepare multipart header
$ranges[$key][0] = "\r\n--" . BYTESERVING_BOUNDARY . "\r\nContent-Type: {$mimetype}\r\n";
$ranges[$key][0] .= "Content-Range: bytes {$ranges[$key][1]}-{$ranges[$key][2]}/{$filesize}\r\n\r\n";
}
} else {
$ranges = false;
}
if ($ranges) {
byteserving_send_file($stored_file->get_content_file_handle(), $mimetype, $ranges, $filesize);
}
}
} else {
/// Do not byteserve (disabled, strings, text and html files).
header('Accept-Ranges: none');
}
} else {
// Do not cache files in proxies and browsers
if (strpos($CFG->wwwroot, 'https://') === 0) {
//https sites - watch out for IE! KB812935 and KB316431
header('Cache-Control: max-age=10');
header('Expires: ' . gmdate('D, d M Y H:i:s', 0) . ' GMT');
header('Pragma: ');
} else {
//normal http - prevent caching at all cost
header('Cache-Control: private, must-revalidate, pre-check=0, post-check=0, max-age=0');
header('Expires: ' . gmdate('D, d M Y H:i:s', 0) . ' GMT');
header('Pragma: no-cache');
}
header('Accept-Ranges: none');
// Do not allow byteserving when caching disabled
}
if (empty($filter)) {
if ($mimetype == 'text/plain') {
header('Content-Type: Text/plain; charset=utf-8');
//add encoding
} else {
header('Content-Type: ' . $mimetype);
}
header('Content-Length: ' . $filesize);
//flush the buffers - save memory and disable sid rewrite
//this also disables zlib compression
示例3: process_upload_file
/**
* @param stored_file $file
* @param string $encoding
* @param string $delimiter
* @param context $defaultcontext
* @return array
*/
protected function process_upload_file($file, $encoding, $delimiter, $defaultcontext)
{
global $CFG, $DB;
require_once $CFG->libdir . '/csvlib.class.php';
$cohorts = array(0 => array('errors' => array(), 'warnings' => array(), 'data' => array()));
// Read and parse the CSV file using csv library.
$content = $file->get_content();
if (!$content) {
$cohorts[0]['errors'][] = new lang_string('csvemptyfile', 'error');
return $cohorts;
}
$uploadid = csv_import_reader::get_new_iid('uploadcohort');
$cir = new csv_import_reader($uploadid, 'uploadcohort');
$readcount = $cir->load_csv_content($content, $encoding, $delimiter);
unset($content);
if (!$readcount) {
$cohorts[0]['errors'][] = get_string('csvloaderror', 'error', $cir->get_error());
return $cohorts;
}
$columns = $cir->get_columns();
// Check that columns include 'name' and warn about extra columns.
$allowedcolumns = array('contextid', 'name', 'idnumber', 'description', 'descriptionformat', 'visible');
$additionalcolumns = array('context', 'category', 'category_id', 'category_idnumber', 'category_path');
$displaycolumns = array();
$extracolumns = array();
$columnsmapping = array();
foreach ($columns as $i => $columnname) {
$columnnamelower = preg_replace('/ /', '', core_text::strtolower($columnname));
$columnsmapping[$i] = null;
if (in_array($columnnamelower, $allowedcolumns)) {
$displaycolumns[$columnnamelower] = $columnname;
$columnsmapping[$i] = $columnnamelower;
} else {
if (in_array($columnnamelower, $additionalcolumns)) {
$columnsmapping[$i] = $columnnamelower;
} else {
$extracolumns[] = $columnname;
}
}
}
if (!in_array('name', $columnsmapping)) {
$cohorts[0]['errors'][] = new lang_string('namecolumnmissing', 'cohort');
return $cohorts;
}
if ($extracolumns) {
$cohorts[0]['warnings'][] = new lang_string('csvextracolumns', 'cohort', s(join(', ', $extracolumns)));
}
if (!isset($displaycolumns['contextid'])) {
$displaycolumns['contextid'] = 'contextid';
}
$cohorts[0]['data'] = $displaycolumns;
// Parse data rows.
$cir->init();
$rownum = 0;
$idnumbers = array();
$haserrors = false;
$haswarnings = false;
while ($row = $cir->next()) {
$rownum++;
$cohorts[$rownum] = array('errors' => array(), 'warnings' => array(), 'data' => array());
$hash = array();
foreach ($row as $i => $value) {
if ($columnsmapping[$i]) {
$hash[$columnsmapping[$i]] = $value;
}
}
$this->clean_cohort_data($hash);
$warnings = $this->resolve_context($hash, $defaultcontext);
$cohorts[$rownum]['warnings'] = array_merge($cohorts[$rownum]['warnings'], $warnings);
if (!empty($hash['idnumber'])) {
if (isset($idnumbers[$hash['idnumber']]) || $DB->record_exists('cohort', array('idnumber' => $hash['idnumber']))) {
$cohorts[$rownum]['errors'][] = new lang_string('duplicateidnumber', 'cohort');
}
$idnumbers[$hash['idnumber']] = true;
}
if (empty($hash['name'])) {
$cohorts[$rownum]['errors'][] = new lang_string('namefieldempty', 'cohort');
}
$cohorts[$rownum]['data'] = array_intersect_key($hash, $cohorts[0]['data']);
$haserrors = $haserrors || !empty($cohorts[$rownum]['errors']);
$haswarnings = $haswarnings || !empty($cohorts[$rownum]['warnings']);
}
if ($haserrors) {
$cohorts[0]['errors'][] = new lang_string('csvcontainserrors', 'cohort');
}
if ($haswarnings) {
$cohorts[0]['warnings'][] = new lang_string('csvcontainswarnings', 'cohort');
}
return $cohorts;
}
示例4: resize
/**
* Shame that this was nicked from gdlib.php and that there isn't a function I could have used from there.
* Creates a resized version of image and stores copy in file area
*
* @param context $context
* @param string $component
* @param string filearea
* @param int $itemid
* @param stored_file $originalfile
* @param int $newwidth;
* @param int $newheight;
* @return stored_file
*/
public static function resize(\stored_file $originalfile, $resizefilename = false, $newwidth = false, $newheight = false, $jpgquality = 90)
{
if ($resizefilename === false) {
$resizefilename = $originalfile->get_filename();
}
if (!$newwidth && !$newheight) {
return false;
}
$contextid = $originalfile->get_contextid();
$component = $originalfile->get_component();
$filearea = $originalfile->get_filearea();
$itemid = $originalfile->get_itemid();
$imageinfo = (object) $originalfile->get_imageinfo();
$imagefnc = '';
if (empty($imageinfo)) {
return false;
}
// Create temporary image for processing.
$tmpimage = tempnam(sys_get_temp_dir(), 'tmpimg');
\file_put_contents($tmpimage, $originalfile->get_content());
if (!$newheight) {
$m = $imageinfo->height / $imageinfo->width;
// Multiplier to work out $newheight.
$newheight = $newwidth * $m;
} else {
if (!$newwidth) {
$m = $imageinfo->width / $imageinfo->height;
// Multiplier to work out $newwidth.
$newwidth = $newheight * $m;
}
}
$t = null;
switch ($imageinfo->mimetype) {
case 'image/gif':
if (\function_exists('imagecreatefromgif')) {
$im = \imagecreatefromgif($tmpimage);
} else {
\debugging('GIF not supported on this server');
unlink($tmpimage);
return false;
}
// Guess transparent colour from GIF.
$transparent = \imagecolortransparent($im);
if ($transparent != -1) {
$t = \imagecolorsforindex($im, $transparent);
}
break;
case 'image/jpeg':
if (\function_exists('imagecreatefromjpeg')) {
$im = \imagecreatefromjpeg($tmpimage);
} else {
\debugging('JPEG not supported on this server');
unlink($tmpimage);
return false;
}
// If the user uploads a jpeg them we should process as a jpeg if possible.
if (\function_exists('imagejpeg')) {
$imagefnc = 'imagejpeg';
$filters = null;
// Not used.
$quality = $jpgquality;
} else {
if (\function_exists('imagepng')) {
$imagefnc = 'imagepng';
$filters = PNG_NO_FILTER;
$quality = 1;
} else {
\debugging('Jpeg and png not supported on this server, please fix server configuration');
unlink($tmpimage);
return false;
}
}
break;
case 'image/png':
if (\function_exists('imagecreatefrompng')) {
$im = \imagecreatefrompng($tmpimage);
} else {
\debugging('PNG not supported on this server');
unlink($tmpimage);
return false;
}
break;
default:
unlink($tmpimage);
return false;
}
unlink($tmpimage);
//.........这里部分代码省略.........