联系官方销售客服
QQ1835022299
028-61286886
因为程序不支持远程图片水印,想通过oss的图片处理给图片加水印,开启了原图保护后上传图片的时候很多地方无法显示图片,只有通过改代码实现了。为了上传图片后及时显示图片,需要在图片结尾加一个oss的图片处理!300,
在下面文件中修改
diy\dayrui\libraries\Field\Image.php
修改了下面代码增加了.'!300' 图片上传后不显示图片,查看源代码图片后面没有接!300,但是保存文章后会显示图片,并且图片后面接了!300。
$info = array(); if ($value && is_array($value)) { foreach ($value as $i => $id) { $info[$i]['id'] = $id; $info[$i]['file'] = dr_get_file($id).'!300'; } }
下面是文件的源代码
name = '图片上传'; // 字段名称 $this->fieldtype = array('TEXT' => '', 'VARCHAR' => '255'); // TRUE表全部可用字段类型,自定义格式为 array('可用字段类型名称' => '默认长度', ... ) $this->defaulttype = 'VARCHAR'; // 当用户没有选择字段类型时的缺省值 } /** * 字段相关属性参数 * * @paramarray$value值 * @return string */ public function option($option) { $option['count'] = isset($option['count']) ? $option['count'] : 2; $option['width'] = isset($option['width']) ? $option['width'] : '80%'; $option['fieldtype'] = isset($option['fieldtype']) ? $option['fieldtype'] : ''; $option['uploadpath'] = isset($option['uploadpath']) ? $option['uploadpath'] : ''; $option['fieldlength'] = isset($option['fieldlength']) ? $option['fieldlength'] : ''; return ''.fc_lang('[整数]表示固定宽带;[整数%]表示百分比').''.fc_lang('单位MB').''.fc_lang('每次最多上传的文件数量').''; } /** * 字段输出 */ public function output($value) { return dr_string2array($value); } /** * 获取附件id */ public function get_attach_id($value) { return dr_string2array($value); } /** * 字段入库值 */ public function insert_value($field) { $my = $this->ci->post[$field['fieldname']]; $data = array(); if ($my) { foreach ($my as $id) { if ($id) { // 下载远程图片 if (strpos($id, 'http') === 0 && (strpos($id, 'jpg') !== false || strpos($id, 'png') !== false || strpos($id, 'gif') !== false || strpos($id, 'jpeg') !== false) && isset($field['setting']['option']['autodown']) && $field['setting']['option']['autodown']) { // 当前作者 $uid = isset($_POST['data']['uid']) ? (int)$_POST['data']['uid'] : $this->ci->uid; // 附件总大小判断 if ($uid == $this->ci->uid && ($this->ci->member['adminid'] || $this->ci->member_rule['attachsize'])) { $data = $this->ci->db->select_sum('filesize')->where('uid', $uid)->get('attachment')->row_array(); if ($this->ci->member['adminid'] || $data['filesize'] <= $this->ci->member_rule['attachsize'] * 1024 * 1024) { // 可以下载 $file = dr_catcher_data($id); if (!$file) { log_message('error', 'Image字段下载远程图片失败:获取远程数据失败('.$id.')'); } else { $path = SYS_UPLOAD_PATH.'/'.date('Ym', SYS_TIME).'/'; if (!is_dir($path)) { dr_mkdirs($path); } $fileext = strtolower(trim(substr(strrchr($id, '.'), 1, 10))); //扩展名 $filename = substr(md5(time()), 0, 7).rand(100, 999); if (@file_put_contents($path.$filename.'.'.$fileext, $file)) { $info = array( 'file_ext' => '.'.$fileext, 'full_path' => $path.$filename.'.'.$fileext, 'file_size' => filesize($path.$filename.'.'.$fileext)/1024, 'client_name' => $id, ); $this->ci->load->model('attachment_model'); $result = $this->ci->attachment_model->upload($uid, $info); if (is_array($result)) { $id = $result[0]; } else { @unlink($path.$filename.'.'.$fileext); log_message('error', '编辑器下载远程图片失败:'.$result); } } else { log_message('error', '编辑器下载远程图片失败:文件写入失败'); } } } else { // 附件总空间不足 $this->ci->member_model->add_notice($uid, 1, fc_lang('附件可用空间不足,无法下载远程图片')); } } } $data[] = $id; } } } // 第一张作为缩略图 if (isset($_POST['data']['thumb']) && !$_POST['data']['thumb'] && isset($data[0]) && $data[0]) { $this->ci->data[1]['thumb'] = $data[0]; } $this->ci->data[$field['ismain']][$field['fieldname']] = dr_array2string($data); } /** * 附件处理 */ public function attach($data, $_data) { $data = dr_string2array($data); $_data = dr_string2array($_data); if (!isset($_data)) { $_data = array(); } if (!isset($data)) { $data = array(); } // 新旧数据都无附件就跳出 if (!$data && !$_data) { return NULL; } // 新旧数据都一样时表示没做改变就跳出 if ($data === $_data) { return NULL; } // 当无新数据且有旧数据表示删除旧附件 if (!$data && $_data) { return array( array(), $_data ); } // 当无旧数据且有新数据表示增加新附件 if ($data && !$_data) { return array( $data, array() ); } // 剩下的情况就是删除旧文件增加新文件 // 新旧附件的交集,表示固定的 $intersect = @array_intersect($data, $_data); return array( @array_diff($data, $intersect), // 固有的与新文件中的差集表示新增的附件 @array_diff($_data, $intersect), // 固有的与旧文件中的差集表示待删除的附件 ); } /** * 字段表单输入 * * @paramstring$cname字段别名 * @paramstring$name字段名称 * @paramarray$cfg字段配置 * @paramarray$data值 * @return string */ public function input($cname, $name, $cfg, $value = NULL, $id = 0) { // 字段显示名称 $text = (isset($cfg['validate']['required']) && $cfg['validate']['required'] == 1 ? '*' : '').''.$cname.':'; // 显示框宽度设置 $width = isset($cfg['option']['width']) && $cfg['option']['width'] ? $cfg['option']['width'] : '80%'; // 表单附加参数 $attr = isset($cfg['validate']['formattr']) && $cfg['validate']['formattr'] ? $cfg['validate']['formattr'] : ''; // 字段提示信息 $tips = isset($cfg['validate']['tips']) && $cfg['validate']['tips'] ? ''.$cfg['validate']['tips'].'' : ''; // 禁止修改 $disabled = !IS_ADMIN && $id && $value && isset($cfg['validate']['isedit']) && $cfg['validate']['isedit'] ? 'disabled' : ''; // 当字段必填时,加入html5验证标签 if (isset($cfg['validate']['required']) && $cfg['validate']['required'] == 1) { $attr.= ' required="required"'; } // 上传的URL $url = '/index.php?s=member&c=api&m=ajax_upload&name='.$name.'&siteid='.SITE_ID.'&code='.str_replace('=', '', dr_authcode($cfg['option']['size'].'|'.$this->get_upload_path($cfg['option']['uploadpath']), 'ENCODE')); // 字段默认值 $file_value = ''; $value && $value = dr_string2array($value); // 默认值输出 $info = array(); if ($value && is_array($value)) { foreach ($value as $i => $id) { $info[$i]['id'] = $id; $info[$i]['file'] = dr_get_file($id).'!300'; } } $count = max(1, (int)$cfg['option']['count']); // 输出变量 $str =''; $str.= ''; $str.= ''; $str.= ''; $str.= ''.fc_lang('目录中不得包含中文
标签介绍:站点id{siteid}、模块目录{module}、年{y}、月{m}、日{d}
例如:{siteid}/{module}/test/,将附件保存至:uploadfile/站点/模块目录/test目录/附件名称.扩展名').'