当前位置: 首页>>代码示例>>PHP>>正文


PHP stored_file::get_timecreated方法代码示例

本文整理汇总了PHP中stored_file::get_timecreated方法的典型用法代码示例。如果您正苦于以下问题:PHP stored_file::get_timecreated方法的具体用法?PHP stored_file::get_timecreated怎么用?PHP stored_file::get_timecreated使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在stored_file的用法示例。


在下文中一共展示了stored_file::get_timecreated方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: emarking_create_anonymous_page_from_storedfile

function emarking_create_anonymous_page_from_storedfile(stored_file $file, $student)
{
    if (!$file) {
        throw new Exception('Stored file does not exist');
    }
    // Get file storage and copy file to temp folder.
    $fs = get_file_storage();
    $tmppath = $file->copy_content_to_temp('emarking', 'anonymous');
    // Treat the file as an image, get its size and draw a white rectangle.
    $size = getimagesize($tmppath, $info);
    $imagemime = exif_imagetype($tmppath);
    if ($imagemime == IMAGETYPE_PNG) {
        $image = imagecreatefrompng($tmppath);
    } elseif ($imagemime == IMAGETYPE_JPEG) {
        $image = imagecreatefromjpeg($tmppath);
    } else {
        throw new Exception('Unsupported file type for pages');
    }
    if (!$image) {
        throw new Exception('Could not read image from ' . $info[0] . ' ' . $tmppath);
    }
    $white = imagecolorallocate($image, 255, 255, 255);
    $y2 = round($size[1] / 10, 0);
    imagefilledrectangle($image, 0, 0, $size[0], $y2, $white);
    // Save the new image to replace the file.
    if ($imagemime == IMAGETYPE_PNG) {
        if (!imagepng($image, $tmppath)) {
            throw new Exception('Could not save image as PNG to ' . $tmppath);
        }
    } elseif ($imagemime == IMAGETYPE_JPEG) {
        if (!imagejpeg($image, $tmppath, 100)) {
            throw new Exception('Could not save image as JPEG to ' . $tmppath);
        }
    } else {
        throw new Exception('Unsupported file type for saving page');
    }
    clearstatcache();
    $filenameanonymous = emarking_get_anonymous_filename($file->get_filename());
    // Copy file from temp folder to Moodle's filesystem.
    $filerecordanonymous = array('contextid' => $file->get_contextid(), 'component' => 'mod_emarking', 'filearea' => 'pages', 'itemid' => $file->get_itemid(), 'filepath' => '/', 'filename' => $filenameanonymous, 'timecreated' => $file->get_timecreated(), 'timemodified' => time(), 'userid' => $student->id, 'author' => $student->firstname . ' ' . $student->lastname, 'license' => 'allrightsreserved');
    $previousfile = $fs->get_file($file->get_contextid(), 'mod_emarking', 'pages', $file->get_itemid(), '/', $filenameanonymous);
    if ($previousfile) {
        $previousfile->delete();
    }
    $fileinfo = $fs->create_file_from_pathname($filerecordanonymous, $tmppath);
    if (!$fileinfo) {
        throw new Exception('Could not create anonymous version of a stored file');
    }
    return $fileinfo;
}
开发者ID:hansnok,项目名称:emarking,代码行数:50,代码来源:locallib.php

示例2: emarking_create_anonymous_page_from_storedfile

function emarking_create_anonymous_page_from_storedfile(stored_file $file)
{
    if (!$file) {
        throw new Exception('Stored file does not exist');
    }
    // Get file storage and copy file to temp folder.
    $fs = get_file_storage();
    $tmppath = $file->copy_content_to_temp('emarking', 'anonymous');
    // Treat the file as an image, get its size and draw a white rectangle.
    $size = getimagesize($tmppath);
    $image = imagecreatefrompng($tmppath);
    $white = imagecolorallocate($image, 255, 255, 255);
    $y2 = round($size[1] / 10, 0);
    imagefilledrectangle($image, 0, 0, $size[0], $y2, $white);
    // Save the new image to replace the file.
    if (!imagepng($image, $tmppath)) {
        return false;
    }
    clearstatcache();
    $filenameanonymous = emarking_get_anonymous_filename($file->get_filename());
    // Copy file from temp folder to Moodle's filesystem.
    $filerecordanonymous = array('contextid' => $file->get_contextid(), 'component' => 'mod_emarking', 'filearea' => 'pages', 'itemid' => $file->get_itemid(), 'filepath' => '/', 'filename' => $filenameanonymous, 'timecreated' => $file->get_timecreated(), 'timemodified' => time(), 'userid' => $file->get_userid(), 'author' => $file->get_author(), 'license' => 'allrightsreserved');
    $previousfile = $fs->get_file($file->get_contextid(), 'mod_emarking', 'pages', $file->get_itemid(), '/', $filenameanonymous);
    if ($previousfile) {
        $previousfile->delete();
    }
    $fileinfo = $fs->create_file_from_pathname($filerecordanonymous, $tmppath);
    return $fileinfo;
}
开发者ID:sikeze,项目名称:emarking,代码行数:29,代码来源:locallib.php


注:本文中的stored_file::get_timecreated方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。