/** * flash上传初始化 * 初始化swfupload上传中需要的参数 * @param $module 模块名称 * @param $catid 栏目id * @param $args 传递参数 * @param $userid 用户id * @param $groupid 用户组id * @param $isadmin 是否为管理员模式 */ function initupload($module, $catid, $args, $userid, $groupid = '8', $isadmin = '0', $userid_flash = '0') { $grouplist = getcache('grouplist', 'member'); if ($isadmin == 0 && !$grouplist[$groupid]['allowattachment']) { return false; } extract(getswfinit($args)); $siteid = param::get_cookie('siteid'); $site_setting = get_site_setting($siteid); $file_size_limit = $site_setting['upload_maxsize']; $sess_id = SYS_TIME; $admin_url = pc_base::load_config('system', 'admin_url'); $upload_path = empty($admin_url) ? APP_PATH : 'http://' . $admin_url . '/'; $swf_auth_key = md5(pc_base::load_config('system', 'auth_key') . $sess_id); $init = 'var swfu = \'\'; $(document).ready(function(){ swfu = new SWFUpload({ flash_url:"' . JS_PATH . 'swfupload/swfupload.swf?"+Math.random(), upload_url:"' . $upload_path . 'index.php?m=attachment&c=attachments&a=swfupload&dosubmit=1", file_post_name : "Filedata", post_params:{"SWFUPLOADSESSID":"' . $sess_id . '","module":"' . $module . '","catid":"' . $_GET['catid'] . '","userid":"' . $userid . '","siteid":"' . $siteid . '","dosubmit":"1","thumb_width":"' . $thumb_width . '","thumb_height":"' . $thumb_height . '","watermark_enable":"' . $watermark_enable . '","filetype_post":"' . $file_types_post . '","swf_auth_key":"' . $swf_auth_key . '","isadmin":"' . $isadmin . '","groupid":"' . $groupid . '","userid_flash":"' . $userid_flash . '"}, file_size_limit:"' . $file_size_limit . '", file_types:"' . $file_types . '", file_types_description:"All Files", file_upload_limit:"' . $file_upload_limit . '", custom_settings : {progressTarget : "fsUploadProgress",cancelButtonId : "btnCancel"}, button_image_url: "", button_width: 75, button_height: 28, button_placeholder_id: "buttonPlaceHolder", button_text_style: "", button_text_top_padding: 3, button_text_left_padding: 12, button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT, button_cursor: SWFUpload.CURSOR.HAND, file_dialog_start_handler : fileDialogStart, file_queued_handler : fileQueued, file_queue_error_handler:fileQueueError, file_dialog_complete_handler:fileDialogComplete, upload_progress_handler:uploadProgress, upload_error_handler:uploadError, upload_success_handler:uploadSuccess, upload_complete_handler:uploadComplete }); })'; return $init; }
/** * 目录浏览模式添加图片 */ public function album_dir() { if (!$this->admin_username) { return false; } if ($_GET['args']) { extract(getswfinit($_GET['args'])); } $dir = isset($_GET['dir']) && trim($_GET['dir']) ? str_replace(array('..\\', '../', './', '.\\'), '', trim($_GET['dir'])) : ''; $filepath = $this->upload_path . $dir; $list = glob($filepath . '/' . '*'); if (!empty($list)) { rsort($list); } $local = str_replace(array(WEKIT_PATH, BASE_PATH, DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR), array('', '', DIRECTORY_SEPARATOR), $filepath); $url = $dir == '.' || $dir == '' ? $this->upload_url : $this->upload_url . str_replace('.', '', $dir) . '/'; $show_header = true; include $this->view('album_dir'); }
public function upload() { header('Content-Type:text/html;charset=utf-8'); if (IS_POST) { $data = array(); $upload = new \Think\Upload(); $site_setting = get_site_setting(get_siteid()); $upload->maxSize = $site_setting['upload_maxsize'] * 1024; $upload->saveRule = "time"; $upload->allowExts = array_intersect(explode('|', $_POST['filetype_post']), explode('|', $site_setting['upload_allowext'])); $upload->rootPath = UPLOAD_PATH; if (isset($_FILES)) { $info = $upload->upload(); if (!$info) { // 上传错误提示错误信息 $data['status'] = 'error'; $data['error_info'] = $upload->getError(); } else { $attach_info = isset($info['0']) ? $info['0'] : $info['upload']; // 将附件插入附件表 $attach_info = array('name' => empty($attach_info["name"]) ? $attach_info["savename"] : $attach_info["name"], 'path' => UPLOAD_PATH . $attach_info["savepath"] . $attach_info["savename"], 'url' => UPLOAD_URL . $attach_info["savepath"] . $attach_info["savename"], 'size' => $attach_info['size'], 'ext' => $attach_info['ext'], 'upload_time' => time(), 'upload_ip' => get_client_ip()); if (in_array($attach_info['ext'], array('jpg', 'gif', 'png', 'jpeg'))) { // $mine_type = (version_compare(PHP_VERSION, '5.3.0') >= 0) ? finfo_file(finfo_open(FILEINFO_MIME_TYPE), $attach_info['path']) : mime_content_type($attach_info['path']); $mine_type = mime_content_type($attach_info['path']); $compression_filename = D("Attachment")->gd_compression_image(UPLOAD_PATH . $attach_info["savepath"], $mine_type, $attach_info["savename"]); $attach_info['compression_image'] = UPLOAD_PATH . $attach_info["savepath"] . $compression_filename; $attach_info['compression_url'] = UPLOAD_URL . $attach_info["savepath"] . $compression_filename; $image_source = D("Attachment")->gd_create_image($mine_type, $attach_info['path']); if ($image_source) { $attach_info['width'] = imagesx($image_source); $attach_info['height'] = imagesy($image_source); } } if (isset($_SESSION['user_info'])) { $attach_info['user_id'] = $_SESSION['user_info']['id']; $attach_info['category_id'] = 1; } if ($attachment_id = D("Attachment")->add($attach_info)) { $data['attachment_id'] = $attachment_id; $data['stutas'] = 'success'; $attach_info['path'] = $attach_info['url']; $data['attachment_info'] = $attach_info; } else { $data['status'] = 'error'; $data['error_info'] = $upload->getError(); } } } else { $data['stutas'] = 'error'; $data['error_info'] = '请先选择图片!'; } sleep(1); if (isset($_GET['CKEditor'])) { $funcNum = $_GET['CKEditorFuncNum']; $url = $data['attachment_info']['path']; $message = isset($data['error_info']) ? $data['error_info'] : ""; $this->ajaxReturn("<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction({$funcNum}, '{$url}', '{$message}');</script>", 'EVAL'); } else { $this->ajaxReturn(json_encode($data), 'EVAL'); } } else { $args = $_GET['args']; $args = getswfinit($_GET['args']); $site_setting = get_site_setting(get_siteid()); $file_size_limit = sizecount($site_setting['upload_maxsize'] * 1024); $this->assign('file_size_limit', $file_size_limit); $this->assign('args', $args); $this->display(); } }
public function upload() { header('Content-Type:text/html;charset=utf-8'); if (IS_POST) { import("ORG.Net.UploadFile"); $savefolder = '/uploads/' . date("Y/m/d") . "/"; $path = UPLOAD_PATH . $savefolder; $upload = new UploadFile(); // 实例化上传类 $site_setting = get_site_setting(get_siteid()); $upload->maxSize = $site_setting['upload_maxsize'] * 1024; // 设置附件上传大小 $upload->saveRule = "time"; // 文件名设置 $upload->allowExts = array_intersect(explode('|', $_POST['filetype_post']), explode('|', $site_setting['upload_allowext'])); // 设置附件上传类型 $upload->uploadReplace = $overflow; if (!is_dir($path)) { mkdir($path, 0777, true); } $data = array(); $upload->savePath = $path; if (isset($_FILES)) { if (!$upload->upload()) { // 上传错误提示错误信息 $data['status'] = 'error'; $data['error_info'] = $upload->getErrorMsg(); } else { // 上传成功 获取上传文件信息 $info = $upload->getUploadFileInfo(); // 将附件插入附件表 $attach_info = array('name' => $info[0]["name"], 'path' => $savefolder . $info[0]["savename"], 'url' => UPLOAD_URL . $savefolder . $info[0]["savename"], 'size' => $info[0]['size'], 'ext' => $info[0]['extension'], 'upload_time' => time(), 'upload_ip' => get_client_ip()); if (in_array($info[0]['extension'], array('jpg', 'gif', 'png', 'jpeg'))) { $mine_type = mime_content_type($path . $info[0]["savename"]); $compression_filename = D("Attachment")->gd_compression_image($path, $mine_type, $info[0]["savename"]); $attach_info['compression_image'] = $savefolder . $compression_filename; $attachment['compression_url'] = UPLOAD_URL . $savefolder . $compression_filename; $image_source = D("Attachment")->gd_create_image($mine_type, $path . $info[0]["savename"]); if ($image_source) { $attach_info['width'] = imagesx($image_source); $attach_info['height'] = imagesy($image_source); } } if (isset($_SESSION['user_info'])) { $attach_info['userid'] = $_SESSION['user_info']['id']; $attach_info['category_id'] = 1; } if ($attachment_id = D("Attachment")->add($attach_info)) { $data['attachment_id'] = $attachment_id; $data['stutas'] = 'success'; $info[0]['path'] = $attach_info['url']; $data['attachment_info'] = $info[0]; } else { // echo M()->getLastSql(); $data['status'] = 'error'; $data['error_info'] = $upload->getErrorMsg(); } } } else { $data['stutas'] = 'error'; $data['error_info'] = '请先选择图片!'; } sleep(1); if (isset($_GET['CKEditor'])) { $funcNum = $_GET['CKEditorFuncNum']; $url = $data['attachment_info']['path']; $message = isset($data['error_info']) ? $data['error_info'] : ""; exit("<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction({$funcNum}, '{$url}', '{$message}');</script>"); } else { exit(json_encode($data)); } } else { $args = $_GET['args']; $args = getswfinit($_GET['args']); $site_setting = get_site_setting(get_siteid()); $file_size_limit = sizecount($site_setting['upload_maxsize'] * 1024); $this->assign('file_size_limit', $file_size_limit); $this->assign('args', $args); $this->display(); } }
/** * flash上传初始化 * 初始化swfupload上传中需要的参数 * * @param $application 应用名称 * @param $catid 栏目id * @param $args 传递参数 * @param $userid 用户id * @param $groupid 用户组id * @param $isadmin 是否为管理员模式 */ function initupload($application, $catid = 0, $args, $userid, $groupid = '7', $isadmin = '0') { $grouplist = S('member/grouplist'); if ($isadmin == 0 && !$grouplist[$groupid]['allowattachment']) { return false; } extract(getswfinit($args)); $file_size_limit = C('attachment', 'maxsize'); $sess_id = TIME; $swf_auth_key = md5(C('config', 'auth_key') . $sess_id); $init = 'var swfu = \'\'; $(document).ready(function(){ swfu = new SWFUpload({ flash_url:"' . JS_PATH . 'swfupload/swfupload.swf?"+Math.random(), upload_url:"' . SITE_URL . 'index.php?app=attachment&controller=attachments&action=swfupload&dosubmit=1", file_post_name : "Filedata", post_params:{"SWFUPLOADSESSID":"' . $sess_id . '","application":"' . $application . '","catid":"' . $catid . '","userid":"' . $userid . '","dosubmit":"1","thumb_width":"' . $thumb_width . '","thumb_height":"' . $thumb_height . '","watermark_enable":"' . $watermark_enable . '","filetype_post":"' . $file_types_post . '","swf_auth_key":"' . $swf_auth_key . '","isadmin":"' . $isadmin . '","groupid":"' . $groupid . '"}, file_size_limit:"' . $file_size_limit . '", file_types:"' . $file_types . '", file_types_description:"All Files", file_upload_limit:"' . $file_upload_limit . '", custom_settings : {progressTarget : "fsUploadProgress",cancelButtonId : "btnCancel"}, button_image_url: "", button_width: 75, button_height: 28, button_placeholder_id: "buttonPlaceHolder", button_text_style: "", button_text_top_padding: 3, button_text_left_padding: 12, button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT, button_cursor: SWFUpload.CURSOR.HAND, file_dialog_start_handler : fileDialogStart, file_queued_handler : fileQueued, file_queue_error_handler:fileQueueError, file_dialog_complete_handler:fileDialogComplete, upload_progress_handler:uploadProgress, upload_error_handler:uploadError, upload_success_handler:uploadSuccess, upload_complete_handler:uploadComplete }); })'; return $init; }