本文整理汇总了PHP中ilObjFile::getFileType方法的典型用法代码示例。如果您正苦于以下问题:PHP ilObjFile::getFileType方法的具体用法?PHP ilObjFile::getFileType怎么用?PHP ilObjFile::getFileType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ilObjFile
的用法示例。
在下文中一共展示了ilObjFile::getFileType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: start
function start()
{
$this->__buildHeader();
$attribs = array("obj_id" => "il_" . IL_INST_ID . "_file_" . $this->file->getId(), "version" => $this->file->getVersion(), "size" => $this->file->getFileSize(), "type" => $this->file->getFileType());
$this->xmlStartTag("File", $attribs);
$this->xmlElement("Filename", null, $this->file->getFileName());
$this->xmlElement("Title", null, $this->file->getTitle());
$this->xmlElement("Description", null, $this->file->getDescription());
$this->xmlElement("Rating", null, (int) $this->file->hasRating());
if ($this->attachFileContents) {
$filename = $this->file->getDirectory($this->file->getVersion()) . "/" . $this->file->getFileName();
if (@is_file($filename)) {
if ($this->attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_COPY) {
$attribs = array("mode" => "COPY");
copy($filename, $this->target_dir_absolute . "/" . $this->file->getFileName());
$content = $this->target_dir_relative . "/" . $this->file->getFileName();
$this->xmlElement("Content", $attribs, $content);
} elseif ($this->attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_REST) {
$attribs = array('mode' => "REST");
include_once './Services/WebServices/Rest/classes/class.ilRestFileStorage.php';
$fs = new ilRestFileStorage();
$tmpname = $fs->storeFileForRest(base64_encode(@file_get_contents($filename)));
$this->xmlElement("Content", $attribs, $tmpname);
} else {
$content = @file_get_contents($filename);
$attribs = array("mode" => "PLAIN");
if ($this->attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_ZLIB_ENCODED) {
$attribs["mode"] = "ZLIB";
$content = @gzcompress($content, 9);
} elseif ($this->attachFileContents == ilFileXMLWriter::$CONTENT_ATTACH_GZIP_ENCODED) {
$attribs["mode"] = "GZIP";
$content = @gzencode($content, 9);
}
$content = base64_encode($content);
$this->xmlElement("Content", $attribs, $content);
}
}
}
include_once "./Services/History/classes/class.ilHistory.php";
$versions = ilHistory::_getEntriesForObject($this->file->getId(), $this->file->getType());
if (count($versions)) {
$this->xmlStartTag("Versions");
foreach ($versions as $version) {
$info_params = $version["info_params"];
list($filename, $history_id) = split(",", $info_params);
$attribs = array("id" => $history_id, "date" => ilUtil::date_mysql2time($version["date"]), "usr_id" => "il_" . IL_INST_ID . "_usr_" . $version["user_id"]);
$this->xmlElement("Version", $attribs);
}
$this->xmlEndTag("Versions");
}
$this->xmlEndTag("File");
$this->__buildFooter();
return true;
}
示例2: addFile
/**
* add an File with id.
*
* @param string $session_id current session
* @param int $target_id refid of parent in repository
* @param string $file_xml qti xml description of test
*
* @return int reference id in the tree, 0 if not successful
*/
function addFile($sid, $target_id, $file_xml)
{
$this->initAuth($sid);
$this->initIlias();
if (!$this->__checkSession($sid)) {
return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
}
global $rbacsystem, $tree, $ilLog, $ilAccess;
if (!($target_obj =& ilObjectFactory::getInstanceByRefId($target_id, false))) {
return $this->__raiseError('No valid target given.', 'Client');
}
if (ilObject::_isInTrash($target_id)) {
return $this->__raiseError("Parent with ID {$target_id} has been deleted.", 'CLIENT_TARGET_DELETED');
}
// Check access
$allowed_types = array('cat', 'grp', 'crs', 'fold', 'root');
if (!in_array($target_obj->getType(), $allowed_types)) {
return $this->__raiseError('No valid target type. Target must be reference id of "course, group, category or folder"', 'Client');
}
if (!$ilAccess->checkAccess('create', '', $target_id, "file")) {
return $this->__raiseError('No permission to create Files in target ' . $target_id . '!', 'Client');
}
// create object, put it into the tree and use the parser to update the settings
include_once './Modules/File/classes/class.ilFileXMLParser.php';
include_once './Modules/File/classes/class.ilFileException.php';
include_once './Modules/File/classes/class.ilObjFile.php';
$file = new ilObjFile();
try {
$fileXMLParser = new ilFileXMLParser($file, $file_xml);
if ($fileXMLParser->start()) {
global $ilLog;
$ilLog->write(__METHOD__ . ': File type: ' . $file->getFileType());
$file->create();
$file->createReference();
$file->putInTree($target_id);
$file->setPermissions($target_id);
// we now can save the file contents since we know the obj id now.
$fileXMLParser->setFileContents();
#$file->update();
return $file->getRefId();
} else {
return $this->__raiseError("Could not add file", "Server");
}
} catch (ilFileException $exception) {
return $this->__raiseError($exception->getMessage(), $exception->getCode() == ilFileException::$ID_MISMATCH ? "Client" : "Server");
}
}
示例3: create
/**
* create new file list in dom and update page in db
*/
function create()
{
include_once "./Modules/File/classes/class.ilObjFile.php";
// from personal workspace
if (substr($_POST["file_ref_id"], 0, 4) == "wsp_") {
$fileObj = new ilObjFile(substr($_POST["file_ref_id"], 4), false);
} else {
if ($_POST["file_ref_id"] == 0) {
$fileObj = new ilObjFile();
$fileObj->setType("file");
$fileObj->setTitle($_FILES["file"]["name"]);
$fileObj->setDescription("");
$fileObj->setFileName($_FILES["file"]["name"]);
$fileObj->setFileType($_FILES["file"]["type"]);
$fileObj->setFileSize($_FILES["file"]["size"]);
$fileObj->setMode("filelist");
$fileObj->create();
// upload file to filesystem
$fileObj->createDirectory();
$fileObj->raiseUploadError(false);
$fileObj->getUploadFile($_FILES["file"]["tmp_name"], $_FILES["file"]["name"]);
} else {
$fileObj = new ilObjFile($_POST["file_ref_id"]);
}
}
$_SESSION["il_text_lang_" . $_GET["ref_id"]] = $_POST["flst_language"];
//echo "::".is_object($this->dom).":";
$this->content_obj = new ilPCFileList($this->dom);
$this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
$this->content_obj->setListTitle(ilUtil::stripSlashes($_POST["flst_title"]), $_POST["flst_language"]);
$this->content_obj->appendItem($fileObj->getId(), $fileObj->getFileName(), $fileObj->getFileType());
$this->updated = $this->pg_obj->update();
if ($this->updated === true) {
$this->ctrl->returnToParent($this, "jump" . $this->hier_id);
} else {
$this->insert();
}
}
示例4: getExportResources
function getExportResources()
{
$export_files = array();
require_once "./Modules/Scorm2004/classes/class.ilSCORM2004Page.php";
include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
include_once "./Modules/File/classes/class.ilObjFile.php";
$tree = new ilTree($this->slm_object->getId());
$tree->setTableNames('sahs_sc13_tree', 'sahs_sc13_tree_node');
$tree->setTreeTablePK("slm_id");
foreach ($tree->getSubTree($tree->getNodeData($this->node_object->getId()), true, 'page') as $page) {
$page_obj = new ilSCORM2004Page($page["obj_id"]);
$page_obj->buildDom();
$mob_ids = $page_obj->collectMediaObjects(false);
foreach ($mob_ids as $mob_id) {
if ($mob_id > 0 && ilObject::_exists($mob_id)) {
$path = ilObjMediaObject::_lookupStandardItemPath($mob_id, false, false);
$media_obj = new ilObjMediaObject($mob_id);
$export_files[$i]["date"] = $media_obj->getCreateDate();
$export_files[$i]["size"] = @filesize($path);
// could be remote, e.g. youtube video
$export_files[$i]["file"] = $media_obj->getTitle();
$export_files[$i]["type"] = $media_obj->getDescription();
$export_files[$i]["path"] = $path;
$this->ctrl->setParameter($this, "resource", rawurlencode(ilObjMediaObject::_lookupStandardItemPath($mob_id, false, false)));
$export_files[$i]["link"] = $this->ctrl->getLinkTarget($this, "downloadResource");
$i++;
}
}
include_once "./Services/COPage/classes/class.ilPCFileList.php";
$file_ids = ilPCFileList::collectFileItems($page_obj, $page_obj->getDomDoc());
foreach ($file_ids as $file_id) {
$file_obj = new ilObjFile($file_id, false);
$export_files[$i]["date"] = $file_obj->getCreateDate();
$export_files[$i]["size"] = $file_obj->getFileSize();
$export_files[$i]["file"] = $file_obj->getFileName();
$export_files[$i]["type"] = $file_obj->getFileType();
$export_files[$i]["file_id"] = $file_id;
$this->ctrl->setParameter($this, "file_id", $file_id);
$export_files[$i]["link"] = $this->ctrl->getLinkTarget($this, "downloadFile", "");
$i++;
}
unset($page_obj);
}
return $export_files;
}
示例5: 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;
}