Пример #1
0
 public function down_img($url, $mid = 'video')
 {
     $chr = strrchr($url, '.');
     $imgUrl = uniqid();
     $imgPath = $mid . '/' . date(C('upload_style'), time()) . '/';
     $imgPath_s = './' . C('upload_path') . '-s/' . $imgPath;
     $filename = './' . C('upload_path') . '/' . $imgPath . $imgUrl . $chr;
     $get_file = get_collect_file($url);
     if ($get_file) {
         write_file($filename, $get_file);
         //是否添加水印
         if (C('upload_water')) {
             import('ORG.Util.Image');
             Image::water($filename, C('upload_water_img'), '', C('upload_water_pct'), C('upload_water_pos'));
         }
         //是否生成缩略图
         if (C('upload_thumb')) {
             mkdirss($imgPath_s);
             import('ORG.Util.Image');
             Image::thumb($filename, $imgPath_s . $imgUrl . $chr, '', C('upload_thumb_w'), C('upload_thumb_h'), true);
         }
         //是否上传远程
         if (C('upload_ftp')) {
             $this->ftp_upload($imgPath . $imgUrl . $chr);
         }
         return $imgPath . $imgUrl . $chr;
     } else {
         return $url;
     }
 }
Пример #2
0
function write_file($l1, $l2 = '')
{
    $dir = dirname($l1);
    if (!is_dir($dir)) {
        mkdirss($dir);
    }
    return @file_put_contents($l1, $l2);
}
Пример #3
0
function mkdirss($dirs, $mode = 0777)
{
    clearstatcache();
    if (!is_dir($dirs)) {
        mkdirss(dirname($dirs), $mode);
        return @mkdir($dirs, $mode);
    }
    return true;
}
Пример #4
0
 public function updateup()
 {
     $config = $_POST["con"];
     $config['upload_thumb_w'] = abs(intval($config['upload_thumb_w']));
     $config['upload_thumb_h'] = abs(intval($config['upload_thumb_h']));
     $config['upload_water_pct'] = abs(intval($config['upload_water_pct']));
     $config['upload_water_pos'] = abs(intval($config['upload_water_pos']));
     $config['upload_http_down'] = abs(intval($config['upload_http_down']));
     $config['upload_ftp_port'] = abs(intval($config['upload_ftp_port']));
     mkdirss('./' . C('upload_path'));
     $this->updateconfig($config);
 }
Пример #5
0
 public function index()
 {
     $size = $this->input->get('size');
     $arr = explode('/picdata/', REQUEST_URI);
     if (empty($arr[1])) {
         header("location:" . piclink('pic', ''));
         exit;
     }
     $arr[1] = 'attachment/' . $arr[1];
     $arrs = explode('?', $arr[1]);
     $files = FCPATH . $arrs[0];
     if (!file_exists($files)) {
         header("location:" . piclink('pic', ''));
         exit;
     }
     if (!empty($size)) {
         $wh = explode('*', $size);
         $w = intval($wh[0]);
         $h = intval($wh[1]);
         if ($w > 800 || $h > 800) {
             $w = 0;
             $h = 0;
         }
     } else {
         $w = 0;
         $h = 0;
     }
     //没有缩放或者超过800则直接转向指定图片
     if ($w == 0 && $h == 0) {
         header("location:http://" . Web_Url . Web_Path . $arrs[0]);
         exit;
     }
     //判断缓存是否存在
     $file_ext = strtolower(trim(substr(strrchr($arrs[0], '.'), 1)));
     $cachedir = 'cache/suo_pic/' . str_replace("attachment/", "", $arrs[0]) . '_' . $w . '_' . $h . '.' . $file_ext;
     $cachedir = str_replace("//", "/", $cachedir);
     if (file_exists(FCPATH . $cachedir)) {
         //会员头像1小时更新一次
         if (strpos($arrs[0], '/logo/') === FALSE || time() - filemtime(FCPATH . $cachedir) < 3600) {
             header("location:http://" . Web_Url . Web_Path . $cachedir);
             exit;
         }
     }
     //创建缓存文件夹
     $temp = pathinfo(FCPATH . $cachedir);
     mkdirss($temp["dirname"]);
     $params['file'] = $files;
     $params['cache'] = FCPATH . $cachedir;
     //加载库类
     $this->load->library('slpic', $params);
     //生成图片
     $this->slpic->resize($w, $h);
 }
Пример #6
0
 public function upload()
 {
     echo '<div style="font-size:12px; height:30px; line-height:30px">';
     $uppath = './' . C('upload_path') . '/';
     $uppath_s = './' . C('upload_path') . '-s/';
     $mid = trim($_POST['mid']);
     $fileback = !empty($_POST['fileback']) ? trim($_POST['fileback']) : 'picurl';
     if ($mid) {
         $uppath .= $mid . '/';
         $uppath_s .= $mid . '/';
         $backpath = $mid . '/';
     }
     import("ORG.Net.UploadFile");
     $up = new UploadFile();
     //$up->maxSize = 3292200;
     $up->savePath = $uppath;
     $up->saveRule = uniqid;
     $up->uploadReplace = true;
     $up->allowExts = explode(',', C('cms_exts'));
     $up->autoSub = true;
     $up->subType = date;
     $up->dateFormat = C('upload_style');
     if (!$up->upload()) {
         $error = $up->getErrorMsg();
         if ($error == '上传文件类型不允许') {
             $error .= ',可上传<font color=red>' . C('cms_exts') . '</font>';
         }
         exit($error . ' [<a href="?s=Admin/Upload/Show/mid/' . $mid . '/fileback/' . $fileback . '">重新上传</a>]');
         //dump($up->getErrorMsg());
     }
     $uploadList = $up->getUploadFileInfo();
     //是否添加水印
     if (C('upload_water')) {
         import("ORG.Util.Image");
         Image::water($uppath . $uploadList[0]['savename'], C('upload_water_img'), '', C('upload_water_pct'), C('upload_water_pos'));
     }
     //是否生成缩略图
     if (C('upload_thumb')) {
         $thumbdir = substr($uploadList[0]['savename'], 0, strrpos($uploadList[0]['savename'], '/'));
         mkdirss($uppath_s . $thumbdir);
         import("ORG.Util.Image");
         Image::thumb($uppath . $uploadList[0]['savename'], $uppath_s . $uploadList[0]['savename'], '', C('upload_thumb_w'), C('upload_thumb_h'), true);
     }
     //是否远程图片
     if (C('upload_ftp')) {
         $img = D('Down');
         $img->ftp_upload($backpath . $uploadList[0]['savename']);
     }
     echo "<script type='text/javascript'>parent.document.getElementById('" . $fileback . "').value='" . $backpath . $uploadList[0]['savename'] . "';</script>";
     echo '文件<a href="' . $uppath . $uploadList[0]['savename'] . '" target="_blank"><font color=red>' . $uploadList[0]['savename'] . '</font></a>上传成功 [<a href="?s=Admin/Upload/Show/mid/' . $mid . '/fileback/' . $fileback . '">重新上传</a>]';
     echo '</div>';
 }
Пример #7
0
/**
 * 移动文件 move_upload_file
 * @param $path
 * @param null $upfile
 * @return bool
 */
function move_upload_file($path, $upfile = NULL)
{
    if (IS_POST && $upfile) {
        /* 新文件目录 */
        $path = './Uploads/' . $path . '/' . date('Ymd') . '/';
        mkdirss($path);
        /* 移动图片 */
        $upfileArr = explode(',', $upfile);
        foreach ($upfileArr as $v) {
            $file = './Uploads/Temp/' . $v;
            //临时文件
            if (is_file($file)) {
                $newFile = $path . $v;
                //新文件
                $newFile_m = $path . 'm' . $v;
                $image = new \Think\Image();
                $image->open($file);
                $image->thumb(100, 100)->save($newFile_m);
                if (rename($file, $newFile)) {
                    /* 记录文件移动日志 */
                    logs_upload_file('文件移动成功', $newFile);
                } else {
                    /* 记录文件移动日志 */
                    logs_upload_file('文件移动失败', $file);
                }
            }
        }
    }
}
 public function updateweb()
 {
     $con = $_POST["con"];
     if (isset($_POST["con_home"])) {
         $con_home = $_POST["con_home"];
     }
     if (isset($con['web_url'])) {
         $con['web_url'] = getaddxie($con['web_url']);
     }
     if (isset($con['web_path'])) {
         $con['web_path'] = getaddxie($con['web_path']);
     }
     if (isset($con['web_adsensepath'])) {
         $con['web_adsensepath'] = getrexie($con['web_adsensepath']);
     }
     if (isset($con['web_copyright'])) {
         $con['web_copyright'] = stripslashes($con['web_copyright']);
     }
     if (isset($con['web_tongji'])) {
         $con['web_tongji'] = stripslashes($con['web_tongji']);
     }
     if (isset($con['web_admin_pagenum'])) {
         $con['web_admin_pagenum'] = abs(intval($con['web_admin_pagenum']));
     }
     if (isset($con['web_home_pagenum'])) {
         $con['web_home_pagenum'] = abs(intval($con['web_home_pagenum']));
     }
     if (isset($con['web_adsensepath'])) {
         $dir = './' . $con['web_adsensepath'];
         //广告保存目录
         if (!is_dir($dir)) {
             mkdirss($dir);
         }
     }
     if (isset($con_home)) {
         $config = array('con' => $con, 'con_home' => $con_home);
     } else {
         $config = array('con' => $con);
     }
     $this->updateconfig($config);
 }
Пример #9
0
 public function downpic()
 {
     $page = intval($this->input->get('page'));
     $pagejs = intval($this->input->get('pagejs'));
     $sql_string = "SELECT id,pic FROM " . CS_SqlPrefix . "vod where hid=0 and yid=0 and Lower(Left(pic,7))='http://' order by addtime desc";
     $query = $this->db->query($sql_string);
     $total = $query->num_rows();
     if ($page > $pagejs || $total == 0) {
         admin_msg('恭喜您,所有远程图片全部同步完成~!', site_url('vod/admin/vod'), 'ok');
         //操作完成
     }
     if ($page == 0) {
         $page = 1;
     }
     $per_page = 20;
     $totalPages = ceil($total / $per_page);
     // 总页数
     if ($total < $per_page) {
         $per_page = $total;
     }
     if ($pagejs == 0) {
         $pagejs = $totalPages;
     }
     $sql_string .= ' limit 20';
     $query = $this->db->query($sql_string);
     //保存目录
     if (UP_Mode == 1 && UP_Pan != '') {
         $pathpic = UP_Pan . '/attachment/vod/' . date('Ym') . '/' . date('d') . '/';
         $pathpic = str_replace("//", "/", $pathpic);
     } else {
         $pathpic = FCPATH . 'attachment/vod/' . date('Ym') . '/' . date('d') . '/';
     }
     if (!is_dir($pathpic)) {
         mkdirss($pathpic);
     }
     $this->load->library('watermark');
     $this->load->library('csup');
     echo '<LINK href="' . Web_Path . 'packs/admin/css/style.css" type="text/css" rel="stylesheet"><br>';
     echo "<div style='font-size:14px;'>&nbsp;&nbsp;&nbsp;<b>正在开始同步第<font style='color:red; font-size:12px; font-style:italic'>" . $page . "</font>页,共<font style='color:red; font-size:12px; font-style:italic'>" . $pagejs . "</font>页,剩<font style='color:red; font-size:12px; font-style:italic'>" . $totalPages . "</font>页</b><br><br>";
     foreach ($query->result() as $row) {
         $up = 'no';
         if (!empty($row->pic)) {
             $picdata = htmlall($row->pic);
             $file_ext = strtolower(trim(substr(strrchr($row->pic, '.'), 1)));
             if ($file_ext != 'jpg' && $file_ext != 'png' && $file_ext != 'gif') {
                 $file_ext = 'jpg';
             }
             //新文件名
             $file_name = date("YmdHis") . rand(10000, 99999) . '.' . $file_ext;
             $file_path = $pathpic . $file_name;
             if (!empty($picdata)) {
                 //保存图片
                 if (write_file($file_path, $picdata)) {
                     $up = 'ok';
                     //判断水印
                     if (CS_WaterMark == 1) {
                         $this->watermark->imagewatermark($file_path);
                     }
                     //判断上传方式
                     $res = $this->csup->up($file_path, $file_name);
                     if (!$res) {
                         $up = 'no';
                     }
                 }
             }
         }
         //成功
         if ($up == 'ok') {
             //修改数据库
             $this->db->query("update " . CS_SqlPrefix . "vod set pic='/" . date('Ym') . "/" . date('d') . "/" . $file_name . "' where id=" . $row->id . "");
             echo "&nbsp;&nbsp;&nbsp;&nbsp;同步<font color=red>" . $row->pic . "</font>&nbsp;图片成功!&nbsp;&nbsp;新图片名:<a href=\"" . piclink('vod', '/' . date('Ym') . '/' . date('d') . '/' . $file_name) . "\" target=_blank>" . $file_name . "</a></br>";
         } else {
             //修改数据库
             $this->db->query("update " . CS_SqlPrefix . "vod set pic='' where id=" . $row->id . "");
             echo "&nbsp;&nbsp;&nbsp;&nbsp;<font color=red>" . $row->pic . "</font>远程图片不存在!</br>";
         }
         ob_flush();
         flush();
     }
     echo "&nbsp;&nbsp;&nbsp;&nbsp;第" . $page . "页图片同步完毕,暂停3秒后继续同步......<script language='javascript'>setTimeout('ReadGo();'," . 3000 . ");function ReadGo(){location.href='" . site_url('vod/admin/opt/downpic') . "?page=" . ($page + 1) . "&pagejs=" . $pagejs . "';}</script></div>";
 }
Пример #10
0
 public function init()
 {
     $id = intval($this->input->get('id'));
     if ($id == 0) {
         admin_msg(L('plub_01'), 'javascript:history.back();', 'no');
     }
     //当前版本内容
     $versiondata = read_file(CSCMS . 'lib/Cs_Version.php');
     //创建缓存文件夹
     $dircache = FCPATH . 'cache/upgrade/';
     if (!file_exists($dircache)) {
         mkdirss($dircache);
     }
     $this->load->library('csapp');
     $zip = 'http://www.chshcms.com/down/xia/utf8/' . $id . '.html';
     $zippath = FCPATH . "attachment/other/backup_" . $id . ".zip";
     $files_file = $this->csapp->down($zip, $zippath);
     if ($files_file == '-1') {
         admin_msg(L('plub_02'), 'javascript:history.back();', 'no');
     }
     if ($files_file == '-2') {
         admin_msg(L('plub_03'), 'javascript:history.back();', 'no');
     }
     if ($files_file == '-3') {
         admin_msg(L('plub_04'), 'javascript:history.back();', 'no');
     }
     if ($files_file == '10001') {
         admin_msg(L('plub_05'), 'javascript:history.back();', 'no');
     }
     if ($files_file == '10002') {
         admin_msg(L('plub_06'), 'javascript:history.back();', 'no');
     }
     if (filesize($zippath) == 0) {
         admin_msg(L('plub_07'), 'javascript:history.back();', 'no');
     }
     //解压缩
     $this->load->library('cszip');
     $this->cszip->PclZip($zippath);
     if ($this->cszip->extract(PCLZIP_OPT_PATH, $dircache, PCLZIP_OPT_REPLACE_NEWER) == 0) {
         @unlink($zippath);
         admin_msg(L('plub_08'), 'javascript:history.back();', 'no');
     }
     //覆盖到根目录
     $this->copyfailnum = 0;
     $this->copymsg = array();
     $this->copydir($dircache, FCPATH);
     //检查文件操作权限,是否复制成功
     if ($this->copyfailnum > 0) {
         //如果失败,恢复当前版本
         write_file(CSCMS . 'lib/Cs_Version.php', $versiondata);
         echo '<LINK href="' . base_url() . 'packs/admin/css/style.css" type="text/css" rel="stylesheet"><br>';
         $k = 1;
         foreach ($this->copymsg as $msg) {
             echo '&nbsp;&nbsp;' . $k . '.' . $msg;
             $k++;
         }
         echo '&nbsp;&nbsp;<b style="color:red">' . L('plub_09') . '&nbsp;&nbsp;<a href="' . site_url('upgrade') . '">' . L('plub_10') . '</a</b>';
         @unlink($zippath);
         exit;
     }
     //检测执行SQL语句
     $this->upsql($dircache);
     //删除文件
     @unlink($zippath);
     //删除文件夹
     deldir($dircache);
     //成功提示
     admin_msg(L('plub_11'), site_url('upgrade'));
 }
Пример #11
0
 public function add()
 {
     $ac = $this->input->get('ac', true);
     $op = $this->input->get('op', true);
     $do = $this->input->get('do', true);
     $dir = $this->input->get('dirs', true);
     $file = $this->input->post('file', true);
     if ($op != 'home' && $op != 'user' && $op != 'mobile') {
         $op = 'skins';
     }
     if (empty($dir)) {
         admin_msg(L('plub_01'), 'javascript:history.back();', 'no');
     }
     //模板路径不能为空
     if (empty($ac)) {
         $skin_dir = CSCMS . 'tpl/' . $op . '/' . $dir . '/';
     } else {
         if (!empty($op)) {
             $skin_dir = FCPATH . 'plugins/' . $ac . '/tpl/' . $op . '/' . $dir . '/';
         } else {
             $skin_dir = FCPATH . 'plugins/' . $ac . '/tpl/skins/' . $dir . '/';
         }
     }
     $skin_dir = str_replace("//", "/", $skin_dir);
     if (!is_dir($skin_dir)) {
         admin_msg(L('plub_12'), 'javascript:history.back();', 'no');
         //模板路径不能为空
     }
     if ($do == 'add') {
         if (empty($file)) {
             exit('<script>alert("' . L('plub_16') . '");javascript:history.back();</script>');
         }
         $path = $skin_dir . $file;
         $exts = strtolower(trim(strrchr($file, '.'), '.'));
         if ($exts == 'html' || $exts == 'js' || $exts == 'css') {
             //增加文件
             if (!write_file($path, ' ')) {
                 echo '<script type="text/javascript">alert("' . L('plub_17') . '");top.web_box(2);tparent.document.location.reload();</script>';
             } else {
                 echo '<script type="text/javascript">top.web_box(2);parent.document.location.reload();</script>';
             }
         } else {
             //增加目录
             if (!mkdirss(str_replace(".", "", $path), ' ')) {
                 echo '<script type="text/javascript">alert("' . L('plub_18') . '");top.web_box(2);parent.document.location.reload();</script>';
             } else {
                 echo '<script type="text/javascript">top.web_box(2);parent.document.location.reload();</script>';
             }
         }
         exit;
     } else {
         $data['savelink'] = site_url('skin/add') . "?ac=" . $ac . "&op=" . $op . "&do=add&dirs=" . $dir;
         $this->load->view('skin_add.html', $data);
     }
 }
Пример #12
0
 /**
  * 打印日志
  *
  * @param log 日志内容
  */
 function showlog($log)
 {
     if ($this->enabeLog) {
         $file = $this->File;
         mkdirss($file);
         //创建文件夹
         $filename = $file . date('Ymd') . '.log';
         error_log($log . "\n", 3, $filename);
     }
 }
 public function updateweb()
 {
     $con = $_POST["con"];
     if (isset($_POST["con_home"])) {
         $con_home = $_POST["con_home"];
     }
     if (isset($con['WEB_URL'])) {
         $con['WEB_URL'] = getaddxie($con['WEB_URL']);
     }
     if (isset($con['WEB_PATH'])) {
         $con['WEB_PATH'] = getaddxie($con['WEB_PATH']);
     }
     if (isset($con['WEB_ADSENSEPATH'])) {
         $con['WEB_ADSENSEPATH'] = getrexie($con['WEB_ADSENSEPATH']);
     }
     if (isset($con['web_copyright'])) {
         $con['WEB_COPYRIGHT'] = stripslashes($con['WEB_COPYRIGHT']);
     }
     if (isset($con['WEB_TONGJI'])) {
         $con['WEB_TONGJI'] = stripslashes($con['WEB_TONGJI']);
     }
     if (isset($con['WEB_ADMIN_PAGENUM'])) {
         $con['WEB_ADMIN_PAGENUM'] = abs(intval($con['WEB_ADMIN_PAGENUM']));
     }
     if (isset($con['WEB_HOME_PAGENUM'])) {
         $con['WEB_HOME_PAGENUM'] = abs(intval($con['WEB_HOME_PAGENUM']));
     }
     if (isset($con['WEB_ADSENSEPATH'])) {
         $dir = './' . $con['WEB_ADSENSEPATH'];
         //广告保存目录
         if (!is_dir($dir)) {
             mkdirss($dir);
         }
     }
     if (isset($con_home)) {
         $config = array('con' => $con, 'con_home' => $con_home);
     } else {
         $config = array('con' => $con);
     }
     $this->updateconfig($config);
 }
Пример #14
0
 public function up_save()
 {
     $key = $this->input->post('key', true);
     if (!$this->CsdjUser->User_Login(1, $key)) {
         exit('No Login');
     }
     //检测会员组上传附件权限
     $key = unserialize(stripslashes(sys_auth($key, 'D')));
     $fid = isset($key['fid']) ? intval($key['fid']) : 0;
     if ($fid == 0) {
         exit('You do not have permission to upload attachments of group members!');
     }
     $dir = $this->input->post('dir', true);
     if (empty($dir) || !preg_match('/^[0-9a-zA-Z\\_]*$/', $dir)) {
         $dir = 'other';
     }
     //上传目录
     if (UP_Mode == 1 && UP_Pan != '') {
         $path = UP_Pan . '/attachment/' . $dir . '/' . date('Ym') . '/' . date('d') . '/';
         $path = str_replace("//", "/", $path);
     } else {
         $path = FCPATH . 'attachment/' . $dir . '/' . date('Ym') . '/' . date('d') . '/';
     }
     if (!is_dir($path)) {
         mkdirss($path);
     }
     $tempFile = $_FILES['Filedata']['tmp_name'];
     $file_name = $_FILES['Filedata']['name'];
     $file_size = filesize($tempFile);
     $file_ext = strtolower(trim(substr(strrchr($file_name, '.'), 1)));
     //检查扩展名
     $ext_arr = explode("|", UP_Type);
     if (in_array($file_ext, $ext_arr) === false) {
         exit(L('up_02'));
     } elseif ($file_ext == 'jpg' || $file_ext == 'png' || $file_ext == 'gif' || $file_ext == 'bmp' || $file_ext == 'jpge') {
         list($width, $height, $type, $attr) = getimagesize($tempFile);
         if (intval($width) < 10 || intval($height) < 10 || $type == 4) {
             exit(L('up_03'));
         }
     }
     //PHP上传失败
     if (!empty($_FILES['Filedata']['error'])) {
         switch ($_FILES['Filedata']['error']) {
             case '1':
                 $error = L('up_04');
                 break;
             case '2':
                 $error = L('up_05');
                 break;
             case '3':
                 $error = L('up_06');
                 break;
             case '4':
                 $error = L('up_07');
                 break;
             case '6':
                 $error = L('up_08');
                 break;
             case '7':
                 $error = L('up_09');
                 break;
             case '8':
                 $error = 'File upload stopped by extension。';
                 break;
             case '999':
             default:
                 $error = L('up_10');
         }
         exit($error);
     }
     //新文件名
     //$file_name=date("YmdHis") . rand(10000, 99999) . '.' . $file_ext;
     $file_name = random_string('alnum', 20) . '.' . $file_ext;
     $file_path = $path . $file_name;
     if (move_uploaded_file($tempFile, $file_path) !== false) {
         //上传成功
         $filepath = UP_Mode == 1 ? '/' . date('Ym') . '/' . date('d') . '/' . $file_name : '/' . date('Ymd') . '/' . $file_name;
         //判断水印
         if ($dir != 'links' && CS_WaterMark == 1) {
             if ($file_ext == 'jpg' || $file_ext == 'png' || $file_ext == 'gif' || $file_ext == 'bmp' || $file_ext == 'jpge') {
                 $this->load->library('watermark');
                 $this->watermark->imagewatermark($file_path);
             }
         }
         //判断上传方式
         $this->load->library('csup');
         $res = $this->csup->up($file_path, $file_name);
         if ($res) {
             if (UP_Mode == 0 && ($dir == 'music' || $dir == 'video')) {
                 $filepath = 'attachment/' . $dir . '/' . $filepath;
             }
             exit($filepath);
         } else {
             @unlink($file_path);
             exit('no');
         }
     } else {
         //上传失败
         exit('no');
     }
 }
Пример #15
0
 public function upload($ac)
 {
     $FILES = $_FILES[$ac];
     //文件保存目录路径
     $save_path = FCPATH . '/attachment/bgpic/';
     //定义允许上传的文件扩展名
     $ext_arr = array('gif', 'jpg', 'png');
     //最大文件大小
     $max_size = 2 * 1024 * 1024;
     //PHP上传失败
     if (!empty($FILES['error'])) {
         switch ($FILES['error']) {
             case '1':
                 $error = L('web_05');
                 break;
             case '2':
                 $error = L('web_06');
                 break;
             case '3':
                 $error = L('web_07');
                 break;
             case '4':
                 $error = L('web_08');
                 break;
             case '6':
                 $error = L('web_09');
                 break;
             case '7':
                 $error = L('web_10');
                 break;
             case '8':
                 $error = 'File upload stopped by extension。';
                 break;
             case '999':
             default:
                 $error = L('web_11');
         }
         $this->alert($error);
     }
     //有上传文件时
     if (!empty($_FILES) === false) {
         $this->alert(L('web_12'));
     }
     //原文件名
     $file_name = $FILES['name'];
     //服务器上临时文件名
     $tmp_name = $FILES['tmp_name'];
     //文件大小
     $file_size = $FILES['size'];
     //检查文件名
     if (!$file_name) {
         $this->alert(L('web_13'));
     }
     //检查目录
     if (@is_dir($save_path) === false) {
         $this->alert(L('web_14'));
     }
     //检查目录写权限
     if (@is_writable($save_path) === false) {
         $this->alert(L('web_15'));
     }
     //检查是否已上传
     if (@is_uploaded_file($tmp_name) === false) {
         $this->alert(L('web_16'));
     }
     //检查文件大小
     if ($file_size > $max_size) {
         $this->alert(L('web_17'));
     }
     //获得文件扩展名
     $file_ext = strtolower(trim(substr(strrchr($file_name, '.'), 1)));
     //检查扩展名
     if (in_array($file_ext, $ext_arr) === false) {
         $this->alert(L('web_18', array(implode(",", $ext_arr))));
     }
     $save_path .= date("Ym") . "/" . date("d") . "/";
     if (!file_exists($save_path)) {
         mkdirss($save_path);
     }
     //新文件名
     $this->load->helper('string');
     $new_file_name = random_string('alnum', 10) . '.' . $file_ext;
     //检查图片文件是否正确
     $aa = getimagesize($tmp_name);
     $weight = $aa["0"];
     ////获取图片的宽
     $height = $aa["1"];
     ///获取图片的高
     if (intval($weight) < 1 || intval($height) < 1) {
         @unlink($tmp_name);
         $this->alert(L('web_19'));
     }
     //移动文件
     $file_path = $save_path . $new_file_name;
     if (move_uploaded_file($tmp_name, $file_path) === false) {
         $this->alert(L('web_20'));
     }
     @chmod($file_path, 0644);
     $filepath = UP_Mode == 1 ? '/' . date('Ym') . '/' . date('d') . '/' . $file_name : '/' . date('Ymd') . '/' . $file_name;
     //判断上传方式
     $this->load->library('csup');
     $res = $this->csup->up($file_path, $new_file_name);
     if ($res) {
         return $new_file_name;
     } else {
         @unlink($file_path);
         $this->alert(L('web_20'));
     }
 }
Пример #16
0
 public function logo_save()
 {
     $uid = isset($_SESSION['cscms__id']) ? intval($_SESSION['cscms__id']) : intval($this->cookie->get_cookie('user_id'));
     $tempFile = file_get_contents("php://input");
     $picname = $uid . ".jpg";
     $picdirs = date('Ym') . "/" . date('d') . "/" . $uid . ".jpg";
     $filename = FCPATH . "attachment/logo/" . $picdirs;
     $filepath = UP_Mode == 1 ? '/' . date('Ym') . '/' . date('d') . '/' . $picname : '/' . date('Ymd') . '/' . $picname;
     if (!empty($tempFile) && $uid > 0) {
         //创建当前文件件
         $dir = FCPATH . "attachment/logo/" . date('Ym') . "/" . date('d');
         mkdirss($dir);
         if ($handle = fopen($filename, "w+")) {
             if (!fwrite($handle, $tempFile) == FALSE) {
                 fclose($handle);
             }
         }
         list($width, $height, $type, $attr) = getimagesize($filename);
         if (intval($width) < 10 || intval($height) < 10 || $type == 4) {
             @unlink($filename);
             exit('UploadPicError');
         }
         //判断水印
         if (CS_WaterMark == 1) {
             $this->load->library('watermark');
             $this->watermark->imagewatermark($filename);
         }
         //判断上传方式
         $this->load->library('csup');
         $res = $this->csup->up($filename, $picname);
         if (!$res) {
             @unlink($filename);
             exit('UploadPicError');
         }
         //删除原来的图片
         $pic = getzd('user', 'logo', $uid);
         if ($pic != $filepath) {
             $this->csup->del($pic, 'logo');
         }
         //写入数据库
         $this->db->query("update " . CS_SqlPrefix . "user set logo='" . $filepath . "' where id=" . $uid . "");
         exit('UploadPicSucceed');
     } else {
         exit('UploadPicError');
     }
 }