Exemple #1
0
 /**
  * 下载远程图片
  */
 private function download_images($imgs, $uid = 0, $size = 0)
 {
     $imgs = array_unique($imgs);
     //去除重复图片
     $regex = $replace = array();
     $path = $uid ? 'uploadfiles/member/' . $uid . '/image/' . date('Ym') . '/' : 'uploadfiles/image/' . date('Ym') . '/';
     $this->mkdirs($path);
     //水印
     $config = App::get_config();
     if ($config['SITE_WATERMARK']) {
         $image = Controller::instance('image_lib');
     }
     foreach ($imgs as $img) {
         if ($uid && $size && count_member_size($uid) > $size * 1024 * 1024) {
             continue;
         }
         if (strpos($img, SITE_URL) !== false || substr($img, 0, 7) != 'http://') {
             continue;
         }
         //下载图片
         $fileext = strtolower(trim(substr(strrchr($img, '.'), 1, 10)));
         //扩展名
         $name = $path . md5($img . time()) . '.' . $fileext;
         $content = fn_geturl($img);
         if (empty($content)) {
             continue;
         }
         if (file_put_contents($name, $content)) {
             if ($config['SITE_WATERMARK']) {
                 $image = Controller::instance('image_lib');
                 if ($config['SITE_WATERMARK'] == 1) {
                     $image->set_watermark_alpha($config['SITE_WATERMARK_ALPHA']);
                     $image->make_image_watermark($name, $config['SITE_WATERMARK_POS'], $config['SITE_WATERMARK_IMAGE']);
                 } else {
                     $image->set_text_content($config['SITE_WATERMARK_TEXT']);
                     $image->make_text_watermark($name, $config['SITE_WATERMARK_POS'], $config['SITE_WATERMARK_SIZE']);
                 }
             }
             $regex[] = $img;
             $replace[] = $name;
         }
     }
     return count($regex) > 0 ? array('regex' => $regex, 'replace' => $replace) : null;
 }
 /**
  * 附件管理
  */
 public function attachmentAction()
 {
     $dir = urldecode($this->get('dir'));
     $type = $this->get('type');
     $mdir = 'uploadfiles/member/' . $this->memberinfo['id'] . '/';
     //会员附件目录
     $mdir = $type == 1 ? $mdir . 'file/' : $mdir . 'image/';
     if ($this->checkFileName($dir)) {
         $this->memberMsg(lang('m-con-20'), url('member/content/attachment', array('type' => $type)));
     }
     $dir = substr($dir, 0, 1) == '/' ? substr($dir, 1) : $dir;
     $data = file_list::get_file_list($mdir . $dir . '/');
     $list = array();
     if ($data) {
         foreach ($data as $t) {
             $path = $mdir . $dir . '/' . $t;
             $ext = is_dir($path) ? 'dir' : strtolower(trim(substr(strrchr($t, '.'), 1, 10)));
             $ico = file_exists(basename(VIEW_DIR) . '/admin/images/ext/' . $ext . '.gif') ? $ext . '.gif' : $ext . '.png';
             $info = array();
             if (is_file($path)) {
                 if (strpos($t, '.thumb.') !== false) {
                     continue;
                 }
                 $info = array('ext' => $ext, 'path' => $path, 'time' => date('Y-m-d H:i:s', filemtime($path)), 'size' => formatFileSize(filesize($path), 2));
             }
             $list[] = array('dir' => urlencode($dir . '/' . $t), 'ico' => $ico, 'url' => is_dir($path) ? url('member/content/attachment', array('dir' => urlencode($dir . '/' . $t), 'type' => $type)) : '', 'name' => $t, 'path' => $path, 'info' => $info, 'isimg' => in_array($ext, array('gif', 'jpg', 'png', 'jpeg', 'bmp')) ? 1 : 0, 'isdir' => is_dir($path) ? 1 : 0);
         }
     }
     $this->view->assign(array('dir' => $dir, 'type' => $type, 'list' => $list, 'pdir' => url('member/content/attachment', array('dir' => urlencode(str_replace(basename($dir), '', $dir)), 'type' => $type)), 'istop' => $dir ? 1 : 0, 'countsize' => formatFileSize(count_member_size($this->memberinfo['id'], $type == 1 ? 'file' : 'image'), 2), 'meta_title' => lang('m-con-5') . '-' . lang('member') . '-' . $this->site['SITE_NAME']));
     $this->view->display('member/attachment');
 }
 /**
  * 文件上传
  * @param  $fields		上传字段 'file'
  * @param  $type		文件类型  array(jpg,gif)
  * @param  $size		文件大小  MB
  * @param  $img			图片配置参数
  * @param  $mark		图片水印
  * @param  $admin		是否来自后台
  * @param  $stype		上传方式  swf或者ke
  * @param  $ofile		原文件
  * @param  $document	后台栏目归档目录
  * @return Array		返回数组
  */
 private function upload($fields, $type, $size, $img = null, $mark = true, $admin = 0, $stype = null, $ofile = null, $document = null)
 {
     $path = 'uploadfiles/';
     $upload = $this->instance('file_upload');
     if (empty($admin) && $this->memberinfo) {
         $uid = $this->memberinfo['id'];
         //会员附件归类
         if ($uid) {
             $path .= 'member/' . $uid . '/';
             if (isset($this->membergroup[$this->memberinfo['groupid']]['filesize']) && $this->membergroup[$this->memberinfo['groupid']]['filesize']) {
                 $c = count_member_size($this->memberinfo['id']);
                 if ($c > $this->membergroup[$this->memberinfo['groupid']]['filesize'] * 1024 * 1024) {
                     $this->attMsg(lang('att-7', array('1' => $this->membergroup[$this->memberinfo['groupid']]['filesize'], '2' => formatFileSize($c))), $stype);
                 }
             }
         }
         $document = null;
     } elseif ($admin) {
         $uid = (int) get_cookie('member_id');
     } else {
         //$this->attMsg(lang('att-0'), $stype);
         $uid = 0;
         $patp = 'uploadfiles/guest/';
     }
     $upload->set($_FILES[$fields])->set_limit_size(1024 * 1024 * $size)->set_limit_type($type);
     //设置路径和名称
     $ext = $upload->fileext();
     if (stripos($ext, 'php') !== FALSE) {
         return array('result' => '文件格式被系统禁止');
     }
     if (in_array($ext, array('jpg', 'jpeg', 'bmp', 'png', 'gif'))) {
         $dir = 'image';
         $upload->set_image($img['w'], $img['h'], $img['t']);
     } else {
         $dir = 'file';
     }
     $path .= $dir . '/' . (empty($document) || $document == 'undefined' || !preg_match('/^[a-zA-Z_0-9]+$/', $document) ? '' : $document . '/');
     if ($ofile && is_file($ofile) && strpos($path, dirname(dirname($ofile))) === 0) {
         //判断原文件
         $path = dirname($ofile) . '/';
         $file = $fname = basename($ofile);
     } else {
         $path .= date('Ym') . '/';
         $data = file_list::get_file_list($path);
         $name = count($data) + 1;
         $name = is_file($path . $name . '.' . $ext) ? $name . str_replace('0.', '_', (double) microtime()) : $name;
         $file = $upload->filename();
         $fname = $name . '.' . $ext;
     }
     $result = $upload->upload($path, $fname);
     //上传成功处理图片
     if (!$result && $dir == 'image') {
         $this->watermark($path . $fname);
     }
     return array('result' => $result, 'path' => $path . $fname, 'file' => $file, 'ext' => $dir == 'image' ? 1 : $ext);
 }