CodeIgniter + Uploadify
ã¡ãã£ã¨ããã£ãã®ã§ã¡ã¢çã«ã
CodeIgniterのフォーラムã§ãåæ§ã®äºãæ¸ããã¦ããã®ã ããã¡ãã£ã¨å¤ããããã«ãCodeIgniterã£ã½ãã³ã³ããã¼ã©ã«æ¸ããã¦ããªãã®ã§ã¡ãã£ã¨ä¸æºã ã£ããä½è¨ãªãã¹ãå ¥ã£ã¦ããã
ãã¥ã¼ã¯æ®éã«ã
<input id="file_upload_img" name="file_upload_img" type="file" />
JavaScriptã大差ã¯ç¡ããã'script'ãhttp://ããæ¸ããªãã¨ãã¼ãã£ã«ãã¹ãã®å ´åã«èºããã
$('#file_upload_img').uploadify({ 'uploader' : '/img/uploadify.swf', 'script' : 'http://example/uploadify/upload', 'cancelImg' : '/img/cancel.png', 'folder' : '/uploads', 'onComplete' : function(event, ID, fileObj, response, data) { ... }, 'auto' : true });
ã³ã³ããã¼ã©ã¯/application/controllers/uploadify.phpã¨ãã¦ã¯ã©ã¹ã¨ãã¦é ç½®ã
<?php class Uploadify extends MY_Controller { public function index() { //do nothing redirect('/', 'refresh'); } public function upload() { //uploadify.phpã®ä¸èº« } }
ã¨ã¾ããããã¾ã§ã¯è¯ãã£ãã
ãã§ãããã£ãã®ããApacheã®ãã°ãããªã¯ã¨ã¹ãã¯ããã¦ããäºã確èªã§ããã®ã ããUploadify::upload()ã«è¡ã£ã¦ãããªãäºãä½ã ãããã¨ãã°ãæ©ãã çµæãã·ã¹ãã ã§ã¯è¯ãããã»ãã·ã§ã³ãã§ãã¯ã§å¼¾ããã¦ããã®ã§ããã
ã»ãã·ã§ã³ãã§ãã¯ã¯/application/core/MY_Controller.phpã§è¡ã£ã¦ãã¦ã
<?php class MY_Controller extends CI_Controller { public function __construct() { parent::__construct(); } public function _remap($method, $params = array()) { $CI =& get_instance(); $CI->load->library('session'); $CI->load->helper('url'); if (!isset($this->session->userdata['id'])) { redirect('login', 'refresh'); exit; } return call_user_func_array(array($this, $method), $params); } }
ã¿ããã«ãã¦ããããã§$this->session->userdata['id']ãç¡ããããã°ã¤ã³ãã©ã¼ã ã«ãªãã¤ã¬ã¯ããã¦ããã®ã§ããã
ã¨ããäºã§ããã®åã«
//Uploadify if (get_class($this->session->CI) == 'Uploadify') { return call_user_func_array(array($this, $method), $params); }
ã£ã¦æãã§ããªãã¸ã§ã¯ããUploadifyã®å ´åã¯è¨±å¯ããã®ã§ããã
å¿è«ãããå°ãå³å¯ã«$methodãªããã使ã£ã¦ãè¯ãã¨æããã©ãåãæ¢ããã¯ããã§è§£æ±ºã§ãã¾ãããã¨ã
[追è¨]
.htaccessã§
RewriteEngine on RewriteCond $1 !^(index\.php|img|css|js|uploads|robots\.txt) RewriteRule ^(.*)$ /index.php/$1 [L]
ã¨uploadsãã£ã¬ã¯ããªãç´æ¥åç §ã§ããããã«ãã¨ããªãã¨ã表示ã¨ãã§ãã¾ããã®ã§æ³¨æã