기본 콘텐츠로 건너뛰기

CodeIgniter ckeditor helper

CodeIgniter ckeditor helper

applications/helper/ckeditor_helper.php

- http://kromack.com/ * @package CodeIgniter * @license http://creativecommons.org/licenses/by-nc-sa/3.0/us/ * @tutorial http://kromack.com/developpement-php/codeigniter/ckeditor-helper-for-codeigniter/ * @see http://codeigniter.com/forums/viewthread/127374/ * @version 2010-08-28 * */ /** * This function adds once the CKEditor's config vars * @author Samuel Sanchez * @access private * @param array $data (default: array()) * @return string */ function cke_initialize($data = array()) { $return = ''; if(!defined('CI_CKEDITOR_HELPER_LOADED')) { define('CI_CKEDITOR_HELPER_LOADED', TRUE); $return = ''; $return .= "CKEDITOR_BASEPATH = '" . base_url() . $data['path'] . "/';"; } return $return; } /** * This function create JavaScript instances of CKEditor * @author Samuel Sanchez * @access private * @param array $data (default: array()) * @return string */ function cke_create_instance($data = array()) { $return = " CKEDITOR.replace('" . $data['id'] . "', {"; //Adding config values if(isset($data['config'])) { foreach($data['config'] as $k=>$v) { // Support for extra config parameters if (is_array($v)) { $return .= $k . " : ["; $return .= config_data($v); $return .= "]"; } else { $return .= $k . " : '" . $v . "'"; } if($k !== end(array_keys($data['config']))) { $return .= ","; } } } $return .= '});'; return $return; } /** * This function displays an instance of CKEditor inside a view * @author Samuel Sanchez * @access public * @param array $data (default: array()) * @return string */ function display_ckeditor($data = array()) { // Initialization $return = cke_initialize($data); // Creating a Ckeditor instance $return .= cke_create_instance($data); // Adding styles values if(isset($data['styles'])) { $return .= "CKEDITOR.addStylesSet( 'my_styles_" . $data['id'] . "', ["; foreach($data['styles'] as $k=>$v) { $return .= "{ name : '" . $k . "', element : '" . $v['element'] . "', styles : { "; if(isset($v['styles'])) { foreach($v['styles'] as $k2=>$v2) { $return .= "'" . $k2 . "' : '" . $v2 . "'"; if($k2 !== end(array_keys($v['styles']))) { $return .= ","; } } } $return .= '} }'; if($k !== end(array_keys($data['styles']))) { $return .= ','; } } $return .= ']);'; $return .= "CKEDITOR.instances['" . $data['id'] . "'].config.stylesCombo_stylesSet = 'my_styles_" . $data['id'] . "'; "; } return $return; } /** * config_data function. * This function look for extra config data * * @author ronan * @link http://kromack.com/developpement-php/codeigniter/ckeditor-helper-for-codeigniter/comment-page-5/#comment-545 * @access public * @param array $data. (default: array()) * @return String */ function config_data($data = array()) { $return = ''; foreach ($data as $key) { if (is_array($key)) { $return .= "["; foreach ($key as $string) { $return .= "'" . $string . "'"; if ($string != end(array_values($key))) $return .= ","; } $return .= "]"; } else { $return .= "'".$key."'"; } if ($key != end(array_values($data))) $return .= ","; } return $return; }

usage: (path에는 ckeditor 경로를 넣어준다.)

'content', 'path' => 'ckeditor', 'config' => array( 'width' => '100%', 'height' => '150px', 'filebrowserUploadUrl' => '/pages/upload' ) ))?>

파일 업로드

public function upload() { /* 업로드 설정 */ if (!is_dir("uploads/".date("Ymd"))) mkdir("uploads/".date("Ymd"), 0777); $upload_config = array( 'upload_path' => 'uploads/'.date("Ymd").'/', 'allowed_types' => '*', 'encrypt_name' => true ); $this->load->library('upload', $upload_config); $message = ""; /* 업로드 처리 */ foreach ($_FILES as $field => $file) { if ($file['error'] == 0) { if ($this->upload->do_upload($field)) { $var_name = $field . "_path"; $upload_data = $this->upload->data(); $$var_name = $upload_data['full_path']; $$var_name = preg_replace("#^" . $_SERVER['DOCUMENT_ROOT'] . "#", "", $$var_name); } else { $errors = $this->upload->display_errors(); $message = "파일 업로드 중 오류 발생했습니다. $errors"; } } } echo '' . 'window.parent.CKEDITOR.tools.callFunction(' . $this->input->get('CKEditorFuncNum') . ', ' . '"' . $upload_path . '", ' . '"' . $message . '");' . ''; }

from http://ejnahc.tistory.com/470 by ccl(A) rewrite - 2020-03-06 03:54:32

댓글

이 블로그의 인기 게시물

[PHP] 코드이그니터 - 파일업로드 구현

[PHP] 코드이그니터 - 파일업로드 구현 파일 업로드 이번에 PHP 프레임워크인 코드 이그니터(Codeigniter)를 사용하여 홈페이지를 만드는데 사용한 이미지 업로드용 코드 입니다. upload 라이브러리를 사용하고 app~ 와 같은 위치에 upload 폴더를 만드고 다음 코드를 사용한다음 ajax 로 호출하여 파일을 업로드 합니다. function index() { // Upload 설정 $config['upload_path'] = './upload/'; $config[\'allowed_types\'] = 'gif|jpg|png'; $config['max_size'] = 100; // 100k $config['max_width'] = 1024; $config['max_height'] = 768; $this->load->library('upload', $config); $data = array(); if (! $this->upload->do_upload("service_image")) { $error = array('error' => $this->upload->display_errors()); } else { //$data = array('upload_data' => $this->upload->data()); $this->output->set_output("./upload/".$this->upload->data('file_name')); } } jquery 를 이용한 파일 업로드 호출 코드 function upload() { var datas, xhr; datas = new FormData(); datas.append( 'service_image', $( ...

2017년 1월 스타트업에서 구인할때 주로 원하는 개발 기술

2017년 1월 스타트업에서 구인할때 주로 원하는 개발 기술 php mysql linux android git kotlin gcm/fcm python mssql mongodb amazon aws ios objective-c swift github python c++ django python postgresql amazon aws html5/css3/javascript android java mysql python c++ c# java aws cloud-server dbms node.js postgresql redis nginx react.js hapi.js amazon aws restful-api angularJS jQuery html5/css3/javascript android firebase custom ui component restful-api asp.net c# html css javascript bootstrap angularjs node.js php mongodb redis 프론트엔드 주요 기술 javascript jquery ajax angularjs wbesocket html5/css3/javascript android ios java xcode node.js coffeescript mysql amazon ec2 amazon es3 android ios node.js php python java ios php mysql apache python android redis node.js jquery msa node.js java restful-api linux nosql golang redis nginx ...

이클립스 코드이그나이터 연동 ( eclipse codeigniter )

이클립스 코드이그나이터 연동 ( eclipse codeigniter ) https://ellislab.com/codeigniter/user-guide/installation/downloads.html 위의 사이트에서 코드이그나이터를 다운 받는다. 다운받은 압축 파일을 풀어 준다. 이클립스에서 php 프로젝트를 생성한 공간에 코드이그나이터 압축파일을 복사 붙여넣기 해준다. 위와 같은 화면이 나오면 정상적으로 연동이 된 것 입니다. from http://nahosung.tistory.com/22 by ccl(A) rewrite - 2020-03-06 16:20:55