本文整理汇总了PHP中ilUtil::ilTempnam方法的典型用法代码示例。如果您正苦于以下问题:PHP ilUtil::ilTempnam方法的具体用法?PHP ilUtil::ilTempnam怎么用?PHP ilUtil::ilTempnam使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ilUtil
的用法示例。
在下文中一共展示了ilUtil::ilTempnam方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: renderImages
/**
* Renders the specified object into images.
* The images do not need to be of the preview image size.
*
* @param ilObjFile $obj The object to create images from.
* @return array An array of ilRenderedImage containing the absolute file paths to the images.
*/
protected function renderImages($obj)
{
$numOfPreviews = $this->getMaximumNumberOfPreviews();
// get file path
$filepath = $obj->getFile();
$inputFile = $this->prepareFileForExec($filepath);
// create a temporary file name and remove its extension
$output = str_replace(".tmp", "", ilUtil::ilTempnam());
// use '#' instead of '%' as it gets replaced by 'escapeShellArg' on windows!
$outputFile = $output . "_#02d.png";
// create images with ghostscript (we use PNG here as it has better transparency quality)
// gswin32c -dBATCH -dNOPAUSE -dSAFER -dFirstPage=1 -dLastPage=5 -sDEVICE=pngalpha -dEPSCrop -r72 -o $outputFile $inputFile
// gswin32c -dBATCH -dNOPAUSE -dSAFER -dFirstPage=1 -dLastPage=5 -sDEVICE=jpeg -dJPEGQ=90 -r72 -o $outputFile $inputFile
$args = sprintf("-dBATCH -dNOPAUSE -dSAFER -dFirstPage=1 -dLastPage=%d -sDEVICE=pngalpha -dEPSCrop -r72 -o %s %s", $numOfPreviews, str_replace("#", "%", ilUtil::escapeShellArg($outputFile)), ilUtil::escapeShellArg($inputFile));
ilUtil::execQuoted(PATH_TO_GHOSTSCRIPT, $args);
// was a temporary file created? then delete it
if ($filepath != $inputFile) {
@unlink($inputFile);
}
// check each file and add it
$images = array();
$outputFile = str_replace("#", "%", $outputFile);
for ($i = 1; $i <= $numOfPreviews; $i++) {
$imagePath = sprintf($outputFile, $i);
if (!file_exists($imagePath)) {
break;
}
$images[] = new ilRenderedImage($imagePath);
}
return $images;
}
示例2: storeFileForRest
public function storeFileForRest($content)
{
$tmpname = ilUtil::ilTempnam();
$path = $this->getPath() . '/' . basename($tmpname);
$this->writeToFile($content, $path);
return basename($tmpname);
}
示例3: getXmlRecord
/**
* Get xml record
*
* @param
* @return
*/
function getXmlRecord($a_entity, $a_version, $a_set)
{
global $ilLog;
if ($a_entity == "usr_profile") {
$tmp_dir = ilUtil::ilTempnam();
ilUtil::makeDir($tmp_dir);
include_once "./Services/User/classes/class.ilObjUser.php";
ilObjUser::copyProfilePicturesToDirectory($a_set["Id"], $tmp_dir);
$this->temp_picture_dirs[$a_set["Id"]] = $tmp_dir;
$a_set["Picture"] = $tmp_dir;
}
return $a_set;
}
示例4: prepareFileForExec
/**
* Checks whether the specified file path can be used with exec() commands.
* If the file name is not conform with exec() commands, a temporary file is
* created and the path to that file is returned.
*
* @param string $filepath The path of the file to check.
* @return string The specified file path if conform with exec(); otherwise, the path to a temporary copy of the file.
*/
public function prepareFileForExec($filepath)
{
$pos = strrpos($filepath, "/");
$name = $pos !== false ? substr($filepath, $pos + 1) : $filepath;
// if the file path contains any characters that could cause problems
// we copy the file to a temporary file
$normName = preg_replace("/[^A-Za-z0-9.\\- +_&]/", "", $name);
if ($normName != $name) {
$tempPath = ilUtil::ilTempnam();
if (copy($filepath, $tempPath)) {
return $tempPath;
}
}
return $filepath;
}
示例5: ilImagemapPreview
/**
* ilImagemapPreview constructor
*
* Creates an instance of the ilImagemapPreview class
*
* @param integer $id The database id of a image map question object
* @access public
*/
function ilImagemapPreview($imagemap_filename = "")
{
global $lng;
$this->lng =& $lng;
$this->imagemap_filename = $imagemap_filename;
$this->preview_filename = $preview_filename;
if (!@is_file($this->preview_filename)) {
$extension = ".jpg";
if (preg_match("/.*\\.(png|jpg|gif|jpeg)\$/", $this->imagemap_filename, $matches)) {
$extension = "." . $matches[1];
}
include_once "./Services/Utilities/classes/class.ilUtil.php";
$this->preview_filename = ilUtil::ilTempnam() . $extension;
}
$this->areas = array();
$this->points = array();
$this->linewidth_outer = 4;
$this->linewidth_inner = 2;
}
示例6: saveTempImage
/**
* Saves binary image data to a temporary image file and returns
* the name of the image file on success.
*/
function saveTempImage($image_data, $filename)
{
$tempname = ilUtil::ilTempnam() . $filename;
$fh = fopen($tempname, "wb");
if ($fh == false) {
return "";
}
$imagefile = fwrite($fh, $image_data);
fclose($fh);
return $tempname;
}
示例7: saveUnzip
/**
* saveUnzip object
*
* @access public
*/
function saveUnzip()
{
$zip_form_gui = $this->initZipUploadForm();
if ($this->checkPermissionBool("create", "", "file")) {
if ($zip_form_gui->checkInput()) {
$zip_file = $zip_form_gui->getInput("zip_file");
$adopt_structure = $zip_form_gui->getInput("adopt_structure");
include_once "Services/Utilities/classes/class.ilFileUtils.php";
// Create unzip-directory
$newDir = ilUtil::ilTempnam();
ilUtil::makeDir($newDir);
// Check if permission is granted for creation of object, if necessary
if ($this->id_type != self::WORKSPACE_NODE_ID) {
$type = ilObject::_lookupType((int) $this->parent_id, true);
} else {
$type = ilObject::_lookupType($this->tree->lookupObjectId($this->parent_id), false);
}
$tree = $access_handler = null;
switch ($type) {
// workspace structure
case 'wfld':
case 'wsrt':
$permission = $this->checkPermissionBool("create", "", "wfld");
$containerType = "WorkspaceFolder";
$tree = $this->tree;
$access_handler = $this->getAccessHandler();
break;
// use categories as structure
// use categories as structure
case 'cat':
case 'root':
$permission = $this->checkPermissionBool("create", "", "cat");
$containerType = "Category";
break;
// use folders as structure (in courses)
// use folders as structure (in courses)
default:
$permission = $this->checkPermissionBool("create", "", "fold");
$containerType = "Folder";
break;
}
// processZipFile (
// Dir to unzip,
// Path to uploaded file,
// should a structure be created (+ permission check)?
// ref_id of parent
// object that contains files (folder or category)
// should sendInfo be persistent?)
try {
$processDone = ilFileUtils::processZipFile($newDir, $zip_file["tmp_name"], $adopt_structure && $permission, $this->parent_id, $containerType, $tree, $access_handler);
ilUtil::sendSuccess($this->lng->txt("file_added"), true);
} catch (ilFileUtilsException $e) {
ilUtil::sendFailure($e->getMessage(), true);
}
ilUtil::delDir($newDir);
$this->ctrl->returnToParent($this);
} else {
$zip_form_gui->setValuesByPost();
$this->tpl->setContent($zip_form_gui->getHTML());
}
} else {
$this->ilErr->raiseError($this->lng->txt("permission_denied"), $this->ilErr->MESSAGE);
}
}
示例8: updateResource
/**
* update resource
*
* @access public
* @param string resource "path"
* @param int econtent id
* @param string post content
* @throws ilECSConnectorException
*/
public function updateResource($a_path, $a_econtent_id, $a_post_string)
{
global $ilLog;
$ilLog->write(__METHOD__ . ': Update resource with id ' . $a_econtent_id);
$this->path_postfix = $a_path;
if ($a_econtent_id) {
$this->path_postfix .= '/' . (int) $a_econtent_id;
} else {
throw new ilECSConnectorException('Error calling updateResource: No content id given.');
}
try {
$this->prepareConnection();
$this->addHeader('Content-Type', 'application/json');
$this->addHeader('Accept', 'application/json');
$this->curl->setOpt(CURLOPT_HTTPHEADER, $this->getHeader());
$this->curl->setOpt(CURLOPT_HEADER, true);
$this->curl->setOpt(CURLOPT_PUT, true);
$tempfile = ilUtil::ilTempnam();
$ilLog->write(__METHOD__ . ': Created new tempfile: ' . $tempfile);
$fp = fopen($tempfile, 'w');
fwrite($fp, $a_post_string);
fclose($fp);
$this->curl->setOpt(CURLOPT_UPLOAD, true);
$this->curl->setOpt(CURLOPT_INFILESIZE, filesize($tempfile));
$fp = fopen($tempfile, 'r');
$this->curl->setOpt(CURLOPT_INFILE, $fp);
$res = $this->call();
fclose($fp);
unlink($tempfile);
return new ilECSResult($res);
} catch (ilCurlConnectionException $exc) {
throw new ilECSConnectorException('Error calling ECS service: ' . $exc->getMessage());
}
}
示例9: deliverPDFfromFO
/**
* Delivers a PDF file from a XSL-FO string
*
* @param string $fo The XSL-FO string
* @access public
*/
public function deliverPDFfromFO($fo, $title = null)
{
global $ilLog;
include_once "./Services/Utilities/classes/class.ilUtil.php";
$fo_file = ilUtil::ilTempnam() . ".fo";
$fp = fopen($fo_file, "w");
fwrite($fp, $fo);
fclose($fp);
include_once './Services/WebServices/RPC/classes/class.ilRpcClientFactory.php';
try {
$pdf_base64 = ilRpcClientFactory::factory('RPCTransformationHandler')->ilFO2PDF($fo);
$filename = strlen($title) ? $title : $this->getTitle();
ilUtil::deliverData($pdf_base64->scalar, ilUtil::getASCIIFilename($filename) . ".pdf", "application/pdf", false, true);
return true;
} catch (XML_RPC2_FaultException $e) {
$ilLog->write(__METHOD__ . ': ' . $e->getMessage());
return false;
} catch (Exception $e) {
$ilLog->write(__METHOD__ . ': ' . $e->getMessage());
return false;
}
/*
include_once "./Services/Transformation/classes/class.ilFO2PDF.php";
$fo2pdf = new ilFO2PDF();
$fo2pdf->setFOString($fo);
$result = $fo2pdf->send();
$filename = (strlen($title)) ? $title : $this->getTitle();
ilUtil::deliverData($result, ilUtil::getASCIIFilename($filename) . ".pdf", "application/pdf", false, true);
*/
}
示例10: exportUserSpecificResults
//.........这里部分代码省略.........
// anonymous
array_push($csvrow, $resultset["firstname"]);
array_push($csvrow, $resultset["login"]);
// #10579
if ($this->object->canExportSurveyCode()) {
array_push($csvrow, $user_id);
}
/* #8211
if ($this->object->getAnonymize() == ilObjSurvey::ANONYMIZE_OFF)
{
array_push($csvrow, $resultset["gender"]);
}
*/
$wt = $this->object->getWorkingtimeForParticipant($user_id);
array_push($csvrow, $wt);
$finished = $finished_data[$user_id];
if ((bool) $finished["finished"]) {
array_push($csvrow, ilDatePresentation::formatDate(new ilDateTime($finished["finished_tstamp"], IL_CAL_UNIX)));
} else {
array_push($csvrow, "-");
}
foreach ($questions as $question_id => $question) {
$question->addUserSpecificResultsData($csvrow, $resultset);
}
array_push($csvfile, $csvrow);
}
// #11179
$surveyname = $this->object->getTitle() . " " . $this->lng->txt("svy_eval_user") . " " . date("Y-m-d");
$surveyname = preg_replace("/\\s/", "_", trim($surveyname));
$surveyname = ilUtil::getASCIIFilename($surveyname);
switch ($export_format) {
case self::TYPE_XLS:
include_once "./Services/Excel/classes/class.ilExcelWriterAdapter.php";
$excelfile = ilUtil::ilTempnam();
$adapter = new ilExcelWriterAdapter($excelfile, FALSE);
$workbook = $adapter->getWorkbook();
$workbook->setVersion(8);
// Use Excel97/2000 Format
// Creating a worksheet
$format_bold =& $workbook->addFormat();
$format_bold->setBold();
$format_percent =& $workbook->addFormat();
$format_percent->setNumFormat("0.00%");
$format_datetime =& $workbook->addFormat();
$format_datetime->setNumFormat("DD/MM/YYYY hh:mm:ss");
$format_title =& $workbook->addFormat();
$format_title->setBold();
$format_title->setColor('black');
$format_title->setPattern(1);
$format_title->setFgColor('silver');
$format_title_plain =& $workbook->addFormat();
$format_title_plain->setColor('black');
$format_title_plain->setPattern(1);
$format_title_plain->setFgColor('silver');
// Creating a worksheet
$pages = floor(count($csvfile[0]) / 250) + 1;
$worksheets = array();
for ($i = 0; $i < $pages; $i++) {
$worksheets[$i] =& $workbook->addWorksheet();
}
$row = 0;
include_once "./Services/Excel/classes/class.ilExcelUtils.php";
$contentstartrow = 0;
foreach ($csvfile as $csvrow) {
$col = 0;
if ($row == 0) {
示例11: importObject
/**
* Import repository object export file
*
* @param string absolute filename of temporary upload file
*/
public final function importObject($a_new_obj, $a_tmp_file, $a_filename, $a_type, $a_comp = "", $a_copy_file = false)
{
// create temporary directory
$tmpdir = ilUtil::ilTempnam();
ilUtil::makeDir($tmpdir);
if ($a_copy_file) {
copy($a_tmp_file, $tmpdir . "/" . $a_filename);
} else {
ilUtil::moveUploadedFile($a_tmp_file, $a_filename, $tmpdir . "/" . $a_filename);
}
ilUtil::unzip($tmpdir . "/" . $a_filename);
$dir = $tmpdir . "/" . substr($a_filename, 0, strlen($a_filename) - 4);
$GLOBALS['ilLog']->write(__METHOD__ . ': do import with dir ' . $dir);
$new_id = $this->doImportObject($dir, $a_type, $a_comp, $tmpdir);
// delete temporary directory
ilUtil::delDir($tmpdir);
return $new_id;
}
示例12: getCertificatePath
/**
* Create a temporary path to store the preview
*
* @return string
*/
public function getCertificatePath()
{
if (!$this->temp_dir) {
$tmpdir = ilUtil::ilTempnam();
ilUtil::makeDir($tmpdir);
$this->temp_dir = $tmpdir;
}
return $this->temp_dir;
}
示例13: updateContent
/**
* Updates a content on the Adobe Connect server
*
* @access public
*/
public function updateContent()
{
$this->initFormContent(self::CONTENT_MOD_EDIT, (int) $_GET['content_id']);
if ($this->cform->checkInput()) {
$this->pluginObj->includeClass('class.ilAdobeConnectDuplicateContentException.php');
$this->pluginObj->includeClass('class.ilAdobeConnectContentUploadException.php');
$fdata = $this->cform->getInput('file');
$target = '';
if ($fdata['name'] != '') {
$target = dirname(ilUtil::ilTempnam());
ilUtil::moveUploadedFile($fdata['tmp_name'], $fdata['name'], $target . '/' . $fdata['name']);
}
try {
$title = strlen($this->cform->getInput('tit')) ? $this->cform->getInput('tit') : $fdata['name'];
$this->object->updateContent((int) $_GET['content_id'], $title, $this->cform->getInput('des'));
if ($fdata['name'] != '') {
$curl = curl_init($this->object->uploadContent((int) $_GET['content_id']));
curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
# curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, array('file' => '@' . $target . '/' . $fdata['name']));
$postResult = curl_exec($curl);
curl_close($curl);
@unlink($target . '/' . $fdata['name']);
}
ilUtil::sendSuccess($this->txt('virtualClassroom_content_updated'), true);
$this->showContent();
return true;
} catch (ilAdobeConnectException $e) {
if ($fdata['name'] != '') {
@unlink($target . '/' . $fdata['name']);
}
ilUtil::sendFailure($this->txt($e->getMessage()));
$this->cform->setValuesByPost();
return $this->editItem();
}
} else {
$this->cform->setValuesByPost();
return $this->editItem();
}
}
示例14: sendmail
/**
* send bookmarks as attachment
*/
function sendmail()
{
global $ilUser;
include_once './Services/Mail/classes/class.ilFileDataMail.php';
require_once "Services/Mail/classes/class.ilFormatMail.php";
$mfile = new ilFileDataMail($ilUser->getId());
$umail = new ilFormatMail($ilUser->getId());
$html_content = $this->export(false);
$tempfile = ilUtil::ilTempnam();
$fp = fopen($tempfile, 'w');
fwrite($fp, $html_content);
fclose($fp);
$filename = 'bookmarks.html';
$mfile->copyAttachmentFile($tempfile, $filename);
$umail->savePostData($ilUser->getId(), array($filename), '', '', '', '', '', '', '', 0);
require_once 'Services/Mail/classes/class.ilMailFormCall.php';
ilUtil::redirect(ilMailFormCall::getRedirectTarget($this, '', array(), array('type' => 'attach')));
}
示例15: handlerEndTag
/**
* handler for end of element
*
* @param resource $a_xml_parser xml parser
* @param string $a_name element name
*/
function handlerEndTag($a_xml_parser, $a_name)
{
$this->cdata = trim($this->cdata);
$GLOBALS['ilLog']->write(__METHOD__ . ': ' . $this->cdata);
switch ($a_name) {
case 'File':
$this->result = true;
break;
case 'Filename':
if (strlen($this->cdata) == 0) {
throw new ilFileException("Filename ist missing!");
}
$this->file->setFilename($this->cdata);
$this->file->setTitle($this->cdata);
break;
case 'Title':
$this->file->setTitle(trim($this->cdata));
break;
case 'Description':
$this->file->setDescription(trim($this->cdata));
break;
case 'Content':
$GLOBALS['ilLog']->write($this->mode);
$this->isReadingFile = false;
$baseDecodedFilename = ilUtil::ilTempnam();
if ($this->mode == ilFileXMLParser::$CONTENT_COPY) {
$this->tmpFilename = $this->getImportDirectory() . "/" . $this->cdata;
} elseif ($this->mode == ilFileXMLParser::$CONTENT_REST) {
include_once './Services/WebServices/Rest/classes/class.ilRestFileStorage.php';
$storage = new ilRestFileStorage();
$this->tmpFilename = $storage->getStoredFilePath($this->cdata);
if (!ilFileUtils::fastBase64Decode($this->tmpFilename, $baseDecodedFilename)) {
throw new ilFileException("Base64-Decoding failed", ilFileException::$DECOMPRESSION_FAILED);
}
$this->tmpFilename = $baseDecodedFilename;
} else {
if (!ilFileUtils::fastBase64Decode($this->tmpFilename, $baseDecodedFilename)) {
throw new ilFileException("Base64-Decoding failed", ilFileException::$DECOMPRESSION_FAILED);
}
if ($this->mode == ilFileXMLParser::$CONTENT_GZ_COMPRESSED) {
if (!ilFileUtils::fastGunzip($baseDecodedFilename, $this->tmpFilename)) {
throw new ilFileException("Deflating with fastzunzip failed", ilFileException::$DECOMPRESSION_FAILED);
}
unlink($baseDecodedFilename);
} elseif ($this->mode == ilFileXMLParser::$CONTENT_ZLIB_COMPRESSED) {
if (!ilFileUtils::fastGunzip($baseDecodedFilename, $this->tmpFilename)) {
throw new ilFileException("Deflating with fastDecompress failed", ilFileException::$DECOMPRESSION_FAILED);
}
unlink($baseDecodedFilename);
} else {
$this->tmpFilename = $baseDecodedFilename;
}
}
//$this->content = $content;
$this->file->setFileSize(filesize($this->tmpFilename));
// strlen($this->content));
// if no file type is given => lookup mime type
if (!$this->file->getFileType()) {
global $ilLog;
#$ilLog->write(__METHOD__.': Trying to detect mime type...');
include_once './Services/Utilities/classes/class.ilFileUtils.php';
$this->file->setFileType(ilFileUtils::_lookupMimeType($this->tmpFilename));
}
break;
}
$this->cdata = '';
return;
}