swfupload/swfupload.css" rel="stylesheet" type="text/css" /> <script language="JavaScript" type="text/javascript" src="<?php echo JS_PATH; ?> swfupload/swfupload.js"></script> <script language="JavaScript" type="text/javascript" src="<?php echo JS_PATH; ?> swfupload/fileprogress.js"></script> <script language="JavaScript" type="text/javascript" src="<?php echo JS_PATH; ?> swfupload/handlers.js"></script> <script type="text/javascript"> <?php echo initupload($_GET['module'], $_GET['catid'], $args, $this->userid, $this->groupid, $this->isadmin); ?> </script> <div class="pad-10"> <div class="col-tab"> <ul class="tabBut cu-li"> <li id="tab_swf_1" <?php echo $tab_status; ?> onclick="SwapTab('swf','on','',5,1);">本地文件</li> <?php if ($att_not_used != '') { ?> <li id="tab_swf_5" class="on icon" onclick="SwapTab('swf','on','',5,5);"><?php echo L('att_not_used'); ?>
<?php /** * @file upload.php * @synopsis 上传异步脚本 * @author Yee, <*****@*****.**> * @version 1.0 * @date 2013-07-11 11:02:27 */ /* 此脚本为UploadJS使用 */ require 'init.php'; $type = $_GET['type']; if (!$type) { $up = initupload($path = PATH_ADMIN . '/data/upload'); if ($_FILES['apkfile']['name']) { $returns = $up->put($_FILES['apkfile']); } echo $returns['new_path']; exit; }
public function swfupload() { //网站配置 $config = cache('Config'); //上传个数,允许上传的文件类型,是否允许从已上传中选择,图片高度,图片高度,是否添加水印1是 $args = I('get.args'); //参数验证码 $authkey = I('get.authkey'); //模块 $module = I('get.module', 'content'); //栏目id $catid = I('get.catid', 0, 'intval'); //验证是否可以上传 $status = $this->isUpload($module, $args, $authkey); if (true !== $status) { $this->error($status); } //具体配置参数 $info = explode(",", $args); //是否有已上传文件 $att_not_used = cookie('att_json'); if (empty($att_not_used)) { $tab_status = ' class="on"'; } if (!empty($att_not_used)) { $div_status = ' hidden'; } //参数补充完整 if (empty($info[1])) { //如果允许上传的文件类型为空,启用网站配置的 uploadallowext if ($this->isadmin) { $info[1] = $config['uploadallowext']; } else { $info[1] = $config['qtuploadallowext']; } } //获取临时未处理的图片 $att = $this->att_not_used(); $this->assign("initupload", initupload($this->module, $catid, $info, $this->upuserid, $this->groupid, $this->isadmin)); //上传格式显示 $this->assign("file_types", implode(',', explode('|', $info[1]))); $this->assign("file_size_limit", $this->isadmin ? $config['uploadmaxsize'] : $config['qtuploadmaxsize']); $this->assign("file_upload_limit", (int) $info[0]); //临时未处理的图片 $this->assign("att", $att); $this->assign("tab_status", $tab_status); $this->assign("div_status", $div_status); $this->assign("att_not_used", $att_not_used); $this->assign('module', $this->module); $this->assign('catid', $catid); $this->assign('upuserid', $this->upuserid); $this->assign('upname', $this->upname); $this->assign('groupid', $this->groupid); $this->assign('isadmin', $this->isadmin); //是否添加水印 $this->assign("watermark_enable", (int) $info[5]); $this->display(T('Attachment@Attachments/swfupload')); }
/** * swfupload 上传 * 通过swf上传成功以后回调处理时会调用swfupload_json方法增加cookies! */ public function swfupload() { $Member_group = F("Member_group"); if (IS_POST) { if ($_POST['swf_auth_key'] != md5(C("AUTHCODE") . $_POST['SWFUPLOADSESSID'])) { exit("0,权限认证失败!"); } $isadmin = (int) $this->_post("isadmin"); //检查用户是否有上传权限 if ($isadmin == 0) { $Member_group = F("Member_group"); if ((int) $Member_group[$this->groupid]['allowattachment'] < 1) { exit("0,所在的用户组没有附件上传权限!"); } } $Callback = false; //用户ID $upuserid = (int) $this->_post("uid"); //取得栏目ID $catid = $this->_post("catid"); //取得模块名称 $module = strtolower($this->_post("module")); //上传处理类 $upload = new UploadFile(); $Attachment = service("Attachment", array("module" => $module, "catid" => $catid, "isadmin" => $isadmin)); $Attachment->set_userid($upuserid); //如果允许上传的文件类型为空,启用网站配置的 uploadallowext //允许上传的文件类型,直接使用网站配置的。20120708 if ($isadmin) { $allowExts = CONFIG_UPLOADALLOWEXT; } else { $allowExts = CONFIG_QTUPLOADALLOWEXT; } //设置上传类型 $upload->allowExts = explode("|", $allowExts); //设置上传大小 if ($isadmin) { $upload->maxSize = (int) CONFIG_UPLOADMAXSIZE * 1024; //单位字节 } else { //前台 $upload->maxSize = (int) CONFIG_QTUPLOADMAXSIZE * 1024; //单位字节 } //图片裁减相关设置,如果开启,将不保留原图 if ($this->_post("thumb_width") && $this->_post("thumb_height")) { $upload->thumb = true; $upload->thumbRemoveOrigin = true; } //是否添加水印 post:watermark_enable 等于1也需要加水印 if ((int) $this->_post('watermark_enable')) { $Callback = array(array("AttachmentsAction", "water"), array()); } //设置缩略图最大宽度 $upload->thumbMaxWidth = $this->_post("thumb_width"); //设置缩略图最大高度 $upload->thumbMaxHeight = $this->_post("thumb_height"); //上传目录 可以单独写个方法,根据栏目ID生成相对于栏目目录附件 $this->filepath = $upload->savePath = $Attachment->FilePath(); //开始上传 if ($upload->upload($Callback)) { //上传成功 $info = $upload->getUploadFileInfo(); //写入附件数据库信息 $status = $Attachment->FileData($info[0]); if ($status) { if (in_array($info[0]['extension'], array("jpg", "png", "jpeg", "gif"))) { // 附件ID 附件网站地址 图标(图片时为1) 文件名 echo "{$status}," . $Attachment->filehttp . ",1," . str_replace(array("\\", "/"), "", $info[0]['name']); exit; } else { $fileext = $info[0]['extension']; if ($fileext == 'zip' || $fileext == 'rar') { $fileext = 'rar'; } elseif ($fileext == 'doc' || $fileext == 'docx') { $fileext = 'doc'; } elseif ($fileext == 'xls' || $fileext == 'xlsx') { $fileext = 'xls'; } elseif ($fileext == 'ppt' || $fileext == 'pptx') { $fileext = 'ppt'; } elseif ($fileext == 'flv' || $fileext == 'swf' || $fileext == 'rm' || $fileext == 'rmvb') { $fileext = 'flv'; } else { $fileext = 'do'; } echo "{$status}," . $Attachment->filehttp . "," . $fileext . "," . str_replace(array("\\", "/"), "", $info[0]['name']); exit; } } else { //删除已经上传的图片,这里逻辑还要优化 @unlink($info[0]['savepath'] . $info[0]['savename']); exit("0,上传成功,但写库失败!"); } } else { //上传失败,返回错误 exit("0," . $upload->getErrorMsg()); } } else { //1,允许上传的文件类型,是否允许从已上传中选择,图片高度,图片高度,是否添加水印1是 $args = $this->_get('args'); $authkey = $this->_get('authkey'); $module = $this->_get("module"); if ($this->module_list[ucwords($module)]) { $this->module = strtolower($module); } if (empty($args) || upload_key($args) != $authkey) { $this->error("配置参数有误!"); } if (!$this->isadmin) { $Member_group = F("Member_group"); if ((int) $Member_group[$this->groupid]['allowattachment'] < 1) { $this->error("所在的用户组没有附件上传权限!"); } } $info = explode(",", $args); $this->catid = $this->_get('catid'); $att_not_used = cookie('att_json'); if (empty($att_not_used)) { $tab_status = ' class="on"'; } if (!empty($att_not_used)) { $div_status = ' hidden'; } //参数补充完整 if (empty($info[1])) { //如果允许上传的文件类型为空,启用网站配置的 uploadallowext if ($this->isadmin) { $info[1] = CONFIG_UPLOADALLOWEXT; } else { $info[1] = CONFIG_QTUPLOADALLOWEXT; } } //获取临时未处理的图片 $att = $this->att_not_used(); //var_dump($att);exit; $this->assign("initupload", initupload($this->module, $this->catid, $args, $this->upuserid, $this->groupid, $this->isadmin)); //上传格式显示 $this->assign("file_types", implode(",", explode("|", $info[1]))); $this->assign("file_size_limit", $this->isadmin ? CONFIG_UPLOADMAXSIZE : CONFIG_QTUPLOADMAXSIZE); $this->assign("file_upload_limit", (int) $info[0]); $this->assign("att", $att); $this->assign("tab_status", $tab_status); $this->assign("div_status", $div_status); $this->assign("att_not_used", $att_not_used); $this->assign("watermark_enable", (int) $info[5]); //是否添加水印 $group = defined('GROUP_NAME') ? GROUP_NAME . '/' : ''; $this->display(); } }
echo JS_PATH; ?> swfupload/swfupload.js"></script> <script language="JavaScript" type="text/javascript" src="<?php echo JS_PATH; ?> swfupload/fileprogress.js"></script> <script language="JavaScript" type="text/javascript" src="<?php echo JS_PATH; ?> swfupload/handlers.js"></script> <script type="text/javascript"> <?php echo initupload($_GET['application'], isset($_GET['catid']) ? $_GET['catid'] : '', $args, $this->userid, $this->groupid, $this->isadmin); ?> </script> <div class="pad-10"> <div class="col-tab"> <ul class="tabBut cu-li"> <li id="tab_swf_1" <?php echo isset($tab_status) ? $tab_status : ''; ?> onclick="SwapTab('swf','on','',5,1);"><?php echo L('upload_attachment'); ?> </li> <li id="tab_swf_2" onclick="SwapTab('swf','on','',5,2);"><?php echo L('net_file'); ?>
/** * swfupload 上传 * 通过swf上传成功以后回调处理时会调用swfupload_json方法增加cookies! */ public function swfupload() { //上传个数,允许上传的文件类型,是否允许从已上传中选择,图片高度,图片高度,是否添加水印1是 $args = I('get.args'); //参数验证码 $authkey = I('get.authkey'); //模块 $module = I('get.module', 'contents'); //兼容 if ('content' == $module) { $module = 'contents'; } //栏目id $catid = I('get.catid', 0, 'intval'); //验证是否可以上传 $status = $this->isUpload($module, $args, $authkey); if (true !== $status) { $this->error($status); } //具体配置参数 $info = explode(",", $args); //是否有已上传文件 $att_not_used = cookie('att_json'); if (empty($att_not_used)) { $tab_status = ' class="on"'; } if (!empty($att_not_used)) { $div_status = ' hidden'; } //参数补充完整 if (empty($info[1])) { //如果允许上传的文件类型为空,启用网站配置的 uploadallowext if ($this->isadmin) { $info[1] = CONFIG_UPLOADALLOWEXT; } else { $info[1] = CONFIG_QTUPLOADALLOWEXT; } } //获取临时未处理的图片 $att = $this->att_not_used(); //var_dump($att);exit; $this->assign("initupload", initupload($this->module, $catid, $info, $this->upuserid, $this->groupid, $this->isadmin)); //上传格式显示 $this->assign("file_types", implode(",", explode("|", $info[1]))); $this->assign("file_size_limit", $this->isadmin ? CONFIG_UPLOADMAXSIZE : CONFIG_QTUPLOADMAXSIZE); $this->assign("file_upload_limit", (int) $info[0]); //临时未处理的图片 $this->assign("att", $att); $this->assign("tab_status", $tab_status); $this->assign("div_status", $div_status); $this->assign("att_not_used", $att_not_used); $this->assign('module', $this->module); $this->assign('catid', $catid); $this->assign('upuserid', $this->upuserid); $this->assign('upname', $this->upname); $this->assign('groupid', $this->groupid); $this->assign('isadmin', $this->isadmin); //是否添加水印 $this->assign("watermark_enable", (int) $info[5]); $this->display(BASE_LIB_PATH . 'Tpl/Attachments/swfupload.php'); }