本文整理汇总了PHP中FileHandler::createImageFile方法的典型用法代码示例。如果您正苦于以下问题:PHP FileHandler::createImageFile方法的具体用法?PHP FileHandler::createImageFile怎么用?PHP FileHandler::createImageFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileHandler
的用法示例。
在下文中一共展示了FileHandler::createImageFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getThumbnailPath
/**
* Returns the path to the thumbnail image
*
* If a thumbnail does not already exist, it is generated,
* written to disk and then the new path is returned
*
* @param int $width
* @param int $height
* @param string $thumbnail_type
* @return mixed|string
*/
public function getThumbnailPath($width = 80, $height = 0, $thumbnail_type = '')
{
// If signiture height setting is omitted, create a square
if (!$height) {
$height = $width;
}
// get thumbail generation info on the doc module configuration.
if (!in_array($thumbnail_type, array('crop', 'ratio'))) {
$thumbnail_type = 'ratio';
}
// Define thumbnail information
$thumbnail_path = sprintf('files/cache/thumbnails/%s', getNumberingPath($this->unique_identifier, 3));
$thumbnail_file = sprintf('%s%dx%d.%s.jpg', $thumbnail_path, $width, $height, $thumbnail_type);
// If thumbnail was already created, return path to it
if (is_file($thumbnail_file)) {
return $thumbnail_file;
}
// Retrieve info about original image: path and extension
$source_file = $this->full_image_path;
$ext = pathinfo($source_file, PATHINFO_EXTENSION);
// Create thumbnail
$output = FileHandler::createImageFile($source_file, $thumbnail_file, $width, $height, $ext, $thumbnail_type);
if ($output) {
return $thumbnail_file;
} else {
return '';
}
}
示例2: getThumbnailByUrl
function getThumbnailByUrl($image_url, $width = 80, $height = 0, $thumbnail_type = '')
{
if (!$height) {
$height = $width;
}
if (!in_array($thumbnail_type, array('crop', 'ratio'))) {
$config = $GLOBALS['__document_config__'];
if (!$config) {
$oDocumentModel = getModel('document');
$config = $oDocumentModel->getDocumentConfig();
$GLOBALS['__document_config__'] = $config;
}
$thumbnail_type = $config->thumbnail_type;
}
if (!is_dir('./files/thumbnails/magiccontent_thumbnail')) {
FileHandler::makeDir('./files/thumbnails/magiccontent_thumbnail');
}
$thumbnail_path = sprintf('files/thumbnails/magiccontent_thumbnail/%s', base64_encode($image_url));
$thumbnail_file = sprintf('%s%dx%d.%s.jpg', $thumbnail_path, $width, $height, $thumbnail_type);
$thumbnail_url = Context::getRequestUri() . $thumbnail_file;
if (file_exists($thumbnail_file)) {
if (filesize($thumbnail_file) < 1) {
return false;
} else {
return $thumbnail_url;
}
}
$tmp_file = sprintf('./files/cache/tmp/%s', md5(rand(111111, 999999) . $image_url));
if (!is_dir('./files/cache/tmp')) {
FileHandler::makeDir('./files/cache/tmp');
}
if (!preg_match('/^(http|https):\\/\\//i', $image_url)) {
$image_url = Context::getRequestUri() . $image_url;
}
FileHandler::getRemoteFile($image_url, $tmp_file);
if (!file_exists($tmp_file)) {
return false;
} else {
list($_w, $_h, $_t, $_a) = @getimagesize($tmp_file);
if (!in_array($_t, array(1, 2, 3, 6, 7, 8))) {
FileHandler::writeFile($thumbnail_file, '', 'w');
return false;
}
$source_file = $tmp_file;
}
$output = FileHandler::createImageFile($source_file, $thumbnail_file, $width, $height, 'jpg', $thumbnail_type);
FileHandler::removeFile($source_file);
if ($output) {
return $thumbnail_url;
} else {
FileHandler::writeFile($thumbnail_file, '', 'w');
}
return false;
}
示例3: insertProfileImageFromUrl
private function insertProfileImageFromUrl($member_srl, $url)
{
$oModuleModel =& getModel('module');
$config = $oModuleModel->getModuleConfig('member');
$max_width = $config->profile_image_max_width;
if (!$max_width) {
$max_width = "80";
}
//default 90
$max_height = $config->profile_image_max_height;
if (!$max_height) {
$max_height = "80";
}
//default 20
$target_path = sprintf('files/member_extra_info/profile_image/%s', getNumberingPath($member_srl));
$target_tmpfile = $target_path . "sample.jpg";
FileHandler::makeDir($target_path);
//지정된 URL 로부터 프로필 이미지 가져오기
if (file_exists($target_tmpfile)) {
unlink($target_tmpfile);
}
$this->getProfileImageFromUrl($url, $target_tmpfile);
list($width, $height, $type, $attrs) = @getimagesize($target_tmpfile);
if ($type == 3) {
$ext = 'png';
} elseif ($type == 2) {
$ext = 'jpg';
} else {
$ext = 'gif';
}
$target_filename = sprintf('%s%d.%s', $target_path, $member_srl, $ext);
$target_filename_mask = sprintf('%s%d.%s', $target_path, $member_srl, '*');
array_map('unlink', glob($target_filename_mask));
if ($width > $max_width || $height > $max_height || !$type != 1) {
FileHandler::createImageFile($target_tmpfile, $target_filename, $max_width, $max_height, $ext);
} else {
@copy($target_tmpfile, $target_filename);
}
unlink($target_tmpfile);
}
示例4: getThumbnail
function getThumbnail($file_srl = null, $width = 80, $height = 0, $thumbnail_type = 'crop')
{
$oFileModel = getModel('file');
if (!$file_srl) {
return;
}
if (!$height) {
$height = $width;
}
// Define thumbnail information
$thumbnail_path = sprintf('files/cache/thumbnails/%s', getNumberingPath($file_srl, 3));
$thumbnail_file = sprintf('%s%dx%d.%s.jpg', $thumbnail_path, $width, $height, $thumbnail_type);
$thumbnail_url = Context::getRequestUri() . $thumbnail_file;
// Return false if thumbnail file exists and its size is 0. Otherwise, return its path
if (file_exists($thumbnail_file)) {
if (filesize($thumbnail_file) < 1) {
return false;
} else {
return $thumbnail_url;
}
}
// Target File
$source_file = NULL;
$file = $oFileModel->getFile($file_srl);
if ($file) {
$source_file = $file->uploaded_filename;
}
if ($source_file) {
$output = FileHandler::createImageFile($source_file, $thumbnail_file, $width, $height, 'jpg', $thumbnail_type);
}
// Return its path if a thumbnail is successfully genetated
if ($output) {
return $thumbnail_url;
} else {
FileHandler::writeFile($thumbnail_file, '', 'w');
}
return;
}
示例5: procFileImageResize
/**
* Image resize
*
* @return Object
**/
function procFileImageResize()
{
$source_src = Context::get('source_src');
$width = Context::get('width');
$height = Context::get('height');
$type = Context::get('type');
$output_src = Context::get('output_src');
if (!$source_src || !$width) {
return new Object(-1, 'msg_invalid_request');
}
if (!$output_src) {
$output_src = $source_src . '.resized' . strrchr($source_src, '.');
}
if (!$type) {
$type = 'ratio';
}
if (!$height) {
$height = $width - 1;
}
if (FileHandler::createImageFile($source_src, $output_src, $width, $height, '', 'ratio')) {
$output->info = getimagesize($output_src);
$output->src = $output_src;
} else {
return new Object(-1, 'msg_invalid_request');
}
$this->add('resized_info', $output);
}
示例6: getThumbnail
function getThumbnail($width = 80, $height = 0, $thumbnail_type = '')
{
// return false if no doc exists
if (!$this->comment_srl) {
return;
}
if ($this->isSecret() && !$this->isGranted()) {
return;
}
// If signiture height setting is omitted, create a square
if (!$height) {
$height = $width;
}
// return false if neigher attached file nor image;
if (!$this->hasUploadedFiles() && !preg_match("!<img!is", $this->get('content'))) {
return;
}
// get thumbail generation info on the doc module configuration.
if (!in_array($thumbnail_type, array('crop', 'ratio'))) {
$thumbnail_type = 'crop';
}
// Define thumbnail information
$thumbnail_path = sprintf('files/thumbnails/%s', getNumberingPath($this->comment_srl, 3));
$thumbnail_file = sprintf('%s%dx%d.%s.jpg', $thumbnail_path, $width, $height, $thumbnail_type);
$thumbnail_lockfile = sprintf('%s%dx%d.%s.lock', $thumbnail_path, $width, $height, $thumbnail_type);
$thumbnail_url = Context::getRequestUri() . $thumbnail_file;
// return false if a size of existing thumbnail file is 0. otherwise return the file path
if (file_exists($thumbnail_file) || file_exists($thumbnail_lockfile)) {
if (filesize($thumbnail_file) < 1) {
return FALSE;
} else {
return $thumbnail_url . '?' . date('YmdHis', filemtime($thumbnail_file));
}
}
// Create lockfile to prevent race condition
FileHandler::writeFile($thumbnail_lockfile, '', 'w');
// Target file
$source_file = NULL;
$is_tmp_file = FALSE;
// find an image file among attached files
if ($this->hasUploadedFiles()) {
$file_list = $this->getUploadedFiles();
$first_image = null;
foreach ($file_list as $file) {
if ($file->direct_download !== 'Y') {
continue;
}
if ($file->cover_image === 'Y' && file_exists($file->uploaded_filename)) {
$source_file = $file->uploaded_filename;
break;
}
if ($first_image) {
continue;
}
if (preg_match("/\\.(jpe?g|png|gif|bmp)\$/i", $file->source_filename)) {
if (file_exists($file->uploaded_filename)) {
$first_image = $file->uploaded_filename;
}
}
}
if (!$source_file && $first_image) {
$source_file = $first_image;
}
}
// get an image file from the doc content if no file attached.
if (!$source_file) {
preg_match_all("!<img\\s[^>]*?src=(\"|')([^\"' ]*?)(\"|')!is", $this->get('content'), $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
$target_src = htmlspecialchars_decode(trim($match[2]));
if (preg_match('/\\/(common|modules|widgets|addons|layouts)\\//i', $target_src)) {
continue;
} else {
if (!preg_match('/^https?:\\/\\//i', $target_src)) {
$target_src = Context::getRequestUri() . $target_src;
}
$tmp_file = sprintf('./files/cache/tmp/%d', md5(rand(111111, 999999) . $this->comment_srl));
if (!is_dir('./files/cache/tmp')) {
FileHandler::makeDir('./files/cache/tmp');
}
FileHandler::getRemoteFile($target_src, $tmp_file);
if (!file_exists($tmp_file)) {
continue;
} else {
if ($is_img = @getimagesize($tmp_file)) {
list($_w, $_h, $_t, $_a) = $is_img;
} else {
continue;
}
$source_file = $tmp_file;
$is_tmp_file = TRUE;
break;
}
}
}
}
$output = FileHandler::createImageFile($source_file, $thumbnail_file, $width, $height, 'jpg', $thumbnail_type);
// Remove source file if it was temporary
if ($is_tmp_file) {
FileHandler::removeFile($source_file);
}
//.........这里部分代码省略.........
示例7: _getFiles
/**
* @brief 파일 검색
**/
function _getFiles($target, $module_srls_list, $search_keyword, $page, $list_count, $direct_download = 'Y')
{
if (is_array($module_srls_list)) {
$module_srls = implode(',', $module_srls_list);
} else {
$module_srls = $module_srls_list;
}
if ($target == 'exclude') {
$args->exclude_module_srl = $module_srls;
} else {
$args->module_srl = $module_srls;
}
$args->page = $page;
$args->list_count = $list_count;
$args->page_count = 10;
$args->search_target = 'filename';
$args->search_keyword = $search_keyword;
$args->sort_index = 'files.file_srl';
$args->order_type = 'desc';
$args->isvalid = 'Y';
$args->direct_download = $direct_download == 'Y' ? 'Y' : 'N';
// 대상 문서들을 가져옴
$oFileAdminModel =& getAdminModel('file');
$output = $oFileAdminModel->getFileList($args);
if (!$output->toBool() || !$output->data) {
return $output;
}
$list = array();
foreach ($output->data as $key => $val) {
$obj = null;
$obj->filename = $val->source_filename;
$obj->download_count = $val->download_count;
if (substr($val->download_url, 0, 2) == './') {
$val->download_url = substr($val->download_url, 2);
}
$obj->download_url = Context::getRequestUri() . $val->download_url;
$obj->target_srl = $val->upload_target_srl;
$obj->file_size = $val->file_size;
// 이미지
if (preg_match('/\\.(jpg|jpeg|gif|png)$/i', $val->source_filename)) {
$obj->type = 'image';
$thumbnail_path = sprintf('files/cache/thumbnails/%s', getNumberingPath($val->file_srl, 3));
if (!is_dir($thumbnail_path)) {
FileHandler::makeDir($thumbnail_path);
}
$thumbnail_file = sprintf('%s%dx%d.%s.jpg', $thumbnail_path, 70, 70, 'crop');
$thumbnail_url = Context::getRequestUri() . $thumbnail_file;
if (!file_exists($thumbnail_file)) {
FileHandler::createImageFile($val->uploaded_filename, $thumbnail_file, 70, 70, 'jpg', 'crop');
}
$obj->src = sprintf('<img src="%s" alt="%s" width="%d" height="%d" />', $thumbnail_url, htmlspecialchars($obj->filename), 70, 70);
// 동영상
} elseif (preg_match('/\\.(swf|flv|wmv|avi|mpg|mpeg|asx|asf|mp3)$/i', $val->source_filename)) {
$obj->type = 'multimedia';
$obj->src = sprintf('<script type="text/javascript">displayMultimedia("%s",80,80);</script>', $obj->download_url);
// 기타
} else {
$obj->type = 'binary';
$obj->src = '';
}
$list[] = $obj;
$target_list[] = $val->upload_target_srl;
}
$output->data = $list;
$oDocumentModel =& getModel('document');
$document_list = $oDocumentModel->getDocuments($target_list);
if ($document_list) {
foreach ($document_list as $key => $val) {
foreach ($output->data as $k => $v) {
if ($v->target_srl == $val->document_srl) {
$output->data[$k]->url = $val->getPermanentUrl();
$output->data[$k]->regdate = $val->getRegdate("Y-m-d H:i");
$output->data[$k]->nick_name = $val->getNickName();
}
}
}
}
$oCommentModel =& getModel('comment');
$comment_list = $oCommentModel->getComments($target_list);
if ($comment_list) {
foreach ($comment_list as $key => $val) {
foreach ($output->data as $k => $v) {
if ($v->target_srl == $val->comment_srl) {
$output->data[$k]->url = $val->getPermanentUrl();
$output->data[$k]->regdate = $val->getRegdate("Y-m-d H:i");
$output->data[$k]->nick_name = $val->getNickName();
}
}
}
}
return $output;
}
示例8: getThumbnail
function getThumbnail($width = 80, $height = 0, $thumbnail_type = '')
{
// return false if no doc exists
if (!$this->comment_srl) {
return;
}
// If signiture height setting is omitted, create a square
if (!$height) {
$height = $width;
}
// return false if neigher attached file nor image;
if (!$this->hasUploadedFiles() && !preg_match("!<img!is", $this->get('content'))) {
return;
}
// get thumbail generation info on the doc module configuration.
if (!in_array($thumbnail_type, array('crop', 'ratio'))) {
$thumbnail_type = 'crop';
}
// Define thumbnail information
$thumbnail_path = sprintf('files/thumbnails/%s', getNumberingPath($this->comment_srl, 3));
$thumbnail_file = sprintf('%s%dx%d.%s.jpg', $thumbnail_path, $width, $height, $thumbnail_type);
$thumbnail_url = Context::getRequestUri() . $thumbnail_file;
// return false if a size of existing thumbnail file is 0. otherwise return the file path
if (file_exists($thumbnail_file)) {
if (filesize($thumbnail_file) < 1) {
return FALSE;
} else {
return $thumbnail_url;
}
}
// Target file
$source_file = NULL;
$is_tmp_file = FALSE;
// find an image file among attached files
if ($this->hasUploadedFiles()) {
$file_list = $this->getUploadedFiles();
if (count($file_list)) {
foreach ($file_list as $file) {
if ($file->direct_download != 'Y') {
continue;
}
if (!preg_match("/\\.(jpg|png|jpeg|gif|bmp)\$/i", $file->source_filename)) {
continue;
}
$source_file = $file->uploaded_filename;
if (!file_exists($source_file)) {
$source_file = NULL;
} else {
break;
}
}
}
}
// get an image file from the doc content if no file attached.
if (!$source_file) {
$content = $this->get('content');
$target_src = NULL;
preg_match_all("!src=(\"|')([^\"' ]*?)(\"|')!is", $content, $matches, PREG_SET_ORDER);
$cnt = count($matches);
for ($i = 0; $i < $cnt; $i++) {
$target_src = $matches[$i][2];
if (preg_match('/\\/(common|modules|widgets|addons|layouts)\\//i', $target_src)) {
continue;
} else {
if (!preg_match('/^(http|https):\\/\\//i', $target_src)) {
$target_src = Context::getRequestUri() . $target_src;
}
$tmp_file = sprintf('./files/cache/tmp/%d', md5(rand(111111, 999999) . $this->comment_srl));
FileHandler::makeDir('./files/cache/tmp');
FileHandler::getRemoteFile($target_src, $tmp_file);
if (!file_exists($tmp_file)) {
continue;
} else {
list($_w, $_h, $_t, $_a) = @getimagesize($tmp_file);
if ($_w < $width || $_h < $height) {
continue;
}
$source_file = $tmp_file;
$is_tmp_file = TRUE;
break;
}
}
}
}
$output = FileHandler::createImageFile($source_file, $thumbnail_file, $width, $height, 'jpg', $thumbnail_type);
if ($is_tmp_file) {
FileHandler::removeFile($source_file);
}
// return the thumbnail path if successfully generated.
if ($output) {
return $thumbnail_url;
} else {
FileHandler::writeFile($thumbnail_file, '', 'w');
}
return;
}
示例9: _get
function _get($item)
{
$status = array('items' => 0, 'tags' => 0, 'images' => 0);
$body = Context::convertEncodingStr(FileHandler::getRemoteResource($item->rss_url, null, 3, 'GET', 'application/xml', array('User-Agent' => 'liveXE ( ' . Context::getRequestUri() . ' )')));
if (!$body) {
$this->doUpdateRssCrawlerTime($item->livexe_rss_srl);
return $status;
}
$body = $this->_checkAndCorrectEncodingInPI($body);
$data = $this->parseRss($body);
if (!$data || !count($data)) {
$this->doUpdateRssCrawlerTime($item->livexe_rss_srl);
return $status;
}
$items = array();
for ($i = 0, $c = count($data); $i < $c; $i++) {
unset($get_args);
$get_args->module_srl = $item->module_srl;
$get_args->link = $data[$i]->link;
$output = executeQuery('livexe.getLiveDocumentExists', $get_args);
if ($output->data) {
continue;
}
$items[$data[$i]->link] = $data[$i];
}
if (!count($items)) {
$this->doUpdateRssCrawlerTime($item->livexe_rss_srl);
return $status;
}
$gap = $start = $end = null;
foreach ($items as $link => $obj) {
unset($args);
$args->module_srl = $item->module_srl;
$args->livexe_rss_srl = $item->livexe_rss_srl;
$args->livexe_document_srl = getNextSequence();
$args->member_srl = $item->member_srl;
$args->author = $obj->author;
$args->title = $obj->title;
$args->content = $obj->content;
$args->link = $obj->link;
if (count($obj->tags)) {
$_tag = array();
foreach ($obj->tags as $key => $val) {
$val = trim(str_replace(array(' ', "\t"), '', $val));
if (!$val) {
continue;
}
$_tag[] = $val;
}
$args->tags = implode(',', $_tag);
}
$args->regdate = $obj->regdate;
$args->list_order = $args->livexe_document_srl * -1;
if (preg_match_all('/<img([^>]+)>/is', $args->content, $matches)) {
for ($i = 0, $c = count($matches[1]); $i < $c; $i++) {
if (preg_match('/"(http)([^"]+)"/i', $matches[1][$i], $match)) {
$filename = str_replace(array('"', '&'), array('', '&'), $match[0]);
if ($filename) {
$target = _XE_PATH_ . 'files/cache/tmp/' . $args->livexe_document_srl;
$thumbnail_name = $args->livexe_document_srl . rand(111111, 333333) . '.jpg';
$path = sprintf("./files/attach/images/%s/%s", $item->module_srl, getNumberingPath($args->livexe_document_srl, 3));
FileHandler::getRemoteFile($filename, $target);
list($width, $height, $type, $attrs) = @getimagesize($target);
if ($width > 80 && $height > 80) {
if (FileHandler::createImageFile($target, _XE_PATH_ . $path . $thumbnail_name, 100, 100, 'jpeg', 'crop')) {
$args->thumbnail = $path . $thumbnail_name;
$status['images']++;
}
break;
}
FileHandler::removeFile($target);
}
}
}
}
$output = executeQuery('livexe.insertLiveDocument', $args);
if (!$output->toBool()) {
continue;
}
$status['items']++;
if (!$start) {
$start = strtotime($args->regdate);
} else {
$end = strtotime($args->regdate);
if ($end - $start > $gap) {
$gap = $end - $start;
}
$start = $end;
}
if (!count($obj->tags)) {
continue;
}
foreach ($obj->tags as $tag) {
unset($tag_args);
$tag_args->module_srl = $item->module_srl;
$tag_args->livexe_rss_srl = $item->livexe_rss_srl;
$tag_args->livexe_document_srl = $args->livexe_document_srl;
$tag_args->tag = str_replace(array(' ', "\t"), '', $tag);
$tag_args->regdate = $args->regdate;
$output = executeQuery('livexe.insertLiveTag', $tag_args);
//.........这里部分代码省略.........
示例10: procMaterialInsert
function procMaterialInsert()
{
$var = Context::getRequestVars();
if (!$var->auth || !$var->type) {
return new Object(-1, 'msg_not_permitted');
}
$oMaterialModel =& getModel('material');
$member_srl = $oMaterialModel->getMemberSrlByAuth($var->auth);
if (!$member_srl) {
return new Object(-1, 'msg_invalid_request');
}
if ($var->type == 'img') {
if ($var->image) {
$path = sprintf('files/cache/material/tmp/%s/', getNumberingPath($member_srl));
$filename = basename($var->image);
$file = $path . $filename;
FileHandler::makeDir($path);
FileHandler::getRemoteFile($var->image, $file);
if (file_exists($file)) {
$material_srl = getNextSequence();
$ext = substr(strrchr($filename, '.'), 1);
$ext = array_shift(explode('?', $ext));
// insert file module
$file_info = array();
$file_info['tmp_name'] = $file;
$file_info['name'] = sprintf("%s.%s", $material_srl, $ext);
$oFileController =& getController('file');
$output = $oFileController->insertFile($file_info, $member_srl, $material_srl, 0, true);
if (!$output->toBool()) {
return $output;
}
//set File valid
$oFileController->setFilesValid($output->get('upload_target_srl'));
// delete temp file
FileHandler::removeFile($filename);
$uploaded_filename = $output->get('uploaded_filename');
$_filename = sprintf("%s%s.%%s.%s", preg_replace("/\\/[^\\/]*\$/", "/", $uploaded_filename), $material_srl, $ext);
$s_filename = sprintf($_filename, 'S');
list($w, $h) = @getimagesize($uploaded_filename);
if ($w > $this->thum['S']['width'] || $h > $this->thum['S']['height']) {
FileHandler::createImageFile($uploaded_filename, $s_filename, $this->thum['S']['width'], $h, '', 'ratio');
} else {
FileHandler::copyFile($uploaded_filename, $s_filename);
}
// replace image src
$var->content = str_replace($var->image, $uploaded_filename, $var->content);
} else {
$var->image = null;
}
} else {
return new Object(-1, 'msg_not_select_image');
}
}
// there is no file or copy failed
if ($var->type == 'img' && !$var->image) {
return new Object(-1, 'msg_fail_image_save');
}
$args->material_srl = $material_srl ? $material_srl : getNextSequence();
$args->member_srl = $member_srl;
$args->type = $var->type;
$args->content = $var->content;
$output = executeQuery('material.insertMaterial', $args);
return $output;
}
示例11: mobileFileUpload
//.........这里部分代码省略.........
}
$direct_download = 'Y';
} else {
$path = sprintf("./files/attach/binaries/%s/%s", $module_srl, getNumberingPath($upload_target_srl, 3));
$filename = $path . md5(crypt(rand(1000000, 900000), rand(0, 100)));
$direct_download = 'N';
}
// make dir
if (!FileHandler::makeDir($path)) {
Context::set('msg', Context::getLang('msg_not_permitted_create'));
return;
}
// move file
if (!@move_uploaded_file($file_info['tmp_name'], $filename)) {
$re_name = md5(crypt(rand(1000000, 900000) . $file_info['name']));
$filename = $path . $re_name . '.' . $ext;
if (!@move_uploaded_file($file_info['tmp_name'], $filename)) {
Context::set('msg', Context::getLang('msg_file_upload_error'));
return;
}
}
// image resize
if ($is_img == 'Y' && $img_resize_use) {
$resizeimg = $oMobileexModel->getImgResizeValue($filename, $img_resize_width, $img_resize_height);
if ($resizeimg->width || $resizeimg->height) {
$resize_target_width = $resizeimg->width;
$resize_target_height = $resizeimg->height;
$img_ext = '.' . $ext;
$resize_path = str_replace($img_ext, "", $filename);
$resize_file = $resize_path . '.' . $ext;
$resize_url = Context::getRequestUri() . $resize_file;
// resize
$source_file = $filename;
$resize_img = FileHandler::createImageFile($source_file, $resize_file, $resize_target_width, $resize_target_height, $ext, 'ratio');
$allow_filesize = $oMobileexModel->getAllowedFileSize(@filesize($filename), $module_srl, $upload_target_srl, $upload_type);
if (!$allow_filesize->allowed_filesize || !$allow_filesize->allowed_attach_size) {
FileHandler::removeFile($filename);
if (!$allow_filesize->allowed_filesize) {
Context::set('msg', Context::getLang('msg_not_allowed_filesize'));
} else {
if (!$allow_filesize->allowed_attach_size) {
Context::set('msg', Context::getLang('msg_not_allowed_attach_size'));
}
}
return;
}
}
}
// get member info
$oMemberModel =& getModel('member');
$member_srl = $oMemberModel->getLoggedMemberSrl();
// file info
$args->file_srl = getNextSequence();
$args->upload_target_srl = $upload_target_srl;
$args->module_srl = $module_srl;
$args->direct_download = $direct_download;
$args->source_filename = $file_info['name'];
$args->uploaded_filename = $filename;
$args->download_count = $download_count;
$args->file_size = @filesize($filename);
$args->comment = NULL;
$args->member_srl = $member_srl;
$args->sid = md5(rand(rand(1111111, 4444444), rand(4444445, 9999999)));
$output = executeQuery('file.insertFile', $args);
if (!$output->toBool()) {
Context::set('msg', Context::getLang('msg_file_upload_error'));
示例12: insertPlanetPhoto
/**
* @brief 플래닛 이미지 등록
**/
function insertPlanetPhoto($module_srl, $source)
{
$oPlanetModel =& getModel('planet');
$path = $oPlanetModel->getPlanetPhotoPath($module_srl);
if (!is_dir($path)) {
FileHandler::makeDir($path);
}
$filename = sprintf('%s/%d.jpg', $path, $module_srl);
FileHandler::createImageFile($source, $filename, 96, 96, 'jpg', 'crop');
}
示例13: UploadMmsImage
function UploadMmsImage($document_srl, $ggname, $gg_FILES)
{
@mkdir('files/ggmailing/');
@chmod('files/ggmailing/', 0755);
@mkdir('files/ggmailing/mms/');
@chmod('files/ggmailing/mms/', 0755);
$target_path = 'files/ggmailing/mms/';
// 파일이 없거나 jpeg 이 아니면 되돌려 보냄
if (!$gg_FILES[$ggname]['tmp_name'] || $gg_FILES[$ggname]['type'] != 'image/jpeg') {
$returnUrl = getNotEncodedUrl('', 'module', 'admin', 'act', 'dispGgmailingAdminSmsList');
//$this->setRedirectUrl($returnUrl);
header("Location:" . $returnUrl);
return;
}
$file_tmp_name = $gg_FILES[$ggname]['tmp_name'];
$file_name = $document_srl . '_' . $ggname . '.jpg';
$file_path = $target_path . $file_name;
//일단 파일을 삭제
@unlink($file_path);
@move_uploaded_file($file_tmp_name, $file_path);
//파일 크기가 20k를 넘으면 섬네일 리사이징
if ($gg_FILES[$ggname]['size'] > 20480) {
//리사이징
FileHandler::createImageFile($file_path, $file_path, '176', '144', 'jpg', 'ratio');
}
@chmod($file_path, 0707);
$single_size = 40 * 1024;
$multi_size = 60 * 1024;
$mms_file1 = _XE_PATH_ . "files/ggmailing/mms/" . $document_srl . "_mms_file1.jpg";
$mms_file2 = _XE_PATH_ . "files/ggmailing/mms/" . $document_srl . "_mms_file2.jpg";
$mms_file3 = _XE_PATH_ . "files/ggmailing/mms/" . $document_srl . "_mms_file3.jpg";
if (filesize($file_path) > $single_size) {
@unlink($file_path);
}
if (filesize($mms_file1) + filesize($mms_file2) + filesize($mms_file3) > $multi_size) {
@unlink($file_path);
}
}
示例14: procHomepageInsertCafeBanner
function procHomepageInsertCafeBanner()
{
global $lang;
$oHomepageModel =& getModel('homepage');
$site_srl = Context::get('site_srl');
if (!$site_srl) {
return new Object(-1, 'msg_invalid_request');
}
$title = Context::get('cafe_title');
if (!$title) {
return new Object(-1, sprintf($lang->filter->isnull, $lang->cafe_title));
}
$description = Context::get('cafe_description');
if (!$description) {
return new Object(-1, sprintf($lang->filter->isnull, $lang->cafe_description));
}
// 홈페이지 제목/내용 변경
$homepage_info = $oHomepageModel->getHomepageInfo($site_srl);
if (!$homepage_info->site_srl) {
return new Object(-1, 'msg_invalid_request');
}
$args->title = $title;
$args->description = $description;
$args->layout_srl = $homepage_info->layout_srl;
$args->site_srl = $homepage_info->site_srl;
$output = executeQuery('homepage.updateHomepage', $args);
if (!$output->toBool()) {
return $output;
}
$cafe_banner = Context::get('cafe_banner');
if ($cafe_banner['name']) {
$banner_src = 'files/attach/cafe_banner/' . $homepage_info->site_srl . '.jpg';
FileHandler::createImageFile($cafe_banner['tmp_name'], $banner_src, 100, 100, 'jpg', 'crop');
}
$this->setTemplatePath($this->module_path . 'tpl');
$this->setTemplateFile('redirect.html');
}
示例15: getThumbnail
//.........这里部分代码省略.........
if (!in_array($thumbnail_type, array('crop', 'ratio'))) {
$config = $GLOBALS['__document_config__'];
if (!$config) {
$oDocumentModel = getModel('document');
$config = $oDocumentModel->getDocumentConfig();
$GLOBALS['__document_config__'] = $config;
}
$thumbnail_type = $config->thumbnail_type ?: 'crop';
}
// Define thumbnail information
$thumbnail_path = sprintf('files/thumbnails/%s', getNumberingPath($this->document_srl, 3));
$thumbnail_file = sprintf('%s%dx%d.%s.jpg', $thumbnail_path, $width, $height, $thumbnail_type);
$thumbnail_lockfile = sprintf('%s%dx%d.%s.lock', $thumbnail_path, $width, $height, $thumbnail_type);
$thumbnail_url = Context::getRequestUri() . $thumbnail_file;
// Return false if thumbnail file exists and its size is 0. Otherwise, return its path
if (file_exists($thumbnail_file) || file_exists($thumbnail_lockfile)) {
if (filesize($thumbnail_file) < 1) {
return FALSE;
} else {
return $thumbnail_url . '?' . date('YmdHis', filemtime($thumbnail_file));
}
}
// Create lockfile to prevent race condition
FileHandler::writeFile($thumbnail_lockfile, '', 'w');
// Target File
$source_file = null;
$is_tmp_file = false;
// Find an iamge file among attached files if exists
if ($this->hasUploadedFiles()) {
$file_list = $this->getUploadedFiles();
$first_image = null;
foreach ($file_list as $file) {
if ($file->direct_download !== 'Y') {
continue;
}
if ($file->cover_image === 'Y' && file_exists($file->uploaded_filename)) {
$source_file = $file->uploaded_filename;
break;
}
if ($first_image) {
continue;
}
if (preg_match("/\\.(jpe?g|png|gif|bmp)\$/i", $file->source_filename)) {
if (file_exists($file->uploaded_filename)) {
$first_image = $file->uploaded_filename;
}
}
}
if (!$source_file && $first_image) {
$source_file = $first_image;
}
}
// If not exists, file an image file from the content
if (!$source_file) {
preg_match_all("!<img\\s[^>]*?src=(\"|')([^\"' ]*?)(\"|')!is", $content, $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
$target_src = htmlspecialchars_decode(trim($match[2]));
if (preg_match('/\\/(common|modules|widgets|addons|layouts)\\//i', $target_src)) {
continue;
} else {
if (!preg_match('/^https?:\\/\\//i', $target_src)) {
$target_src = Context::getRequestUri() . $target_src;
}
$tmp_file = sprintf('./files/cache/tmp/%d', md5(rand(111111, 999999) . $this->document_srl));
if (!is_dir('./files/cache/tmp')) {
FileHandler::makeDir('./files/cache/tmp');
}
FileHandler::getRemoteFile($target_src, $tmp_file);
if (!file_exists($tmp_file)) {
continue;
} else {
if ($is_img = @getimagesize($tmp_file)) {
list($_w, $_h, $_t, $_a) = $is_img;
} else {
continue;
}
$source_file = $tmp_file;
$is_tmp_file = true;
break;
}
}
}
}
if ($source_file) {
$output = FileHandler::createImageFile($source_file, $thumbnail_file, $width, $height, 'jpg', $thumbnail_type);
}
// Remove source file if it was temporary
if ($is_tmp_file) {
FileHandler::removeFile($source_file);
}
// Remove lockfile
FileHandler::removeFile($thumbnail_lockfile);
// Return the thumbnail path if it was successfully generated
if ($output) {
return $thumbnail_url . '?' . date('YmdHis');
} else {
FileHandler::writeFile($thumbnail_file, '', 'w');
}
return;
}