コード例 #1
0
function stream_save($strdata, $albumid = 0, $fileext = 'jpg', $name = '', $title = '', $delsize = 0, $from = false)
{
    global $_G, $space;
    if ($albumid < 0) {
        $albumid = 0;
    }
    $setarr = array();
    require_once libfile('class/upload');
    $upload = new discuz_upload();
    $filepath = $upload->get_target_dir('album') . $upload->get_target_filename('album') . '.' . $fileext;
    $newfilename = $_G['setting']['attachdir'] . './album/' . $filepath;
    if ($handle = fopen($newfilename, 'wb')) {
        if (fwrite($handle, $strdata) !== FALSE) {
            fclose($handle);
            $size = filesize($newfilename);
            if (empty($space)) {
                $_G['member'] = $space = getspace($_G['uid']);
                $_G['username'] = addslashes($space['username']);
            }
            $_G['member'] = $space;
            $maxspacesize = checkperm('maxspacesize');
            $maxspacesize = $maxspacesize * 1024 * 1024;
            if ($maxspacesize) {
                space_merge($space, 'common_member_count');
                space_merge($space, 'common_member_field_home');
                if ($space['attachsize'] + $size - $delsize > $maxspacesize + $space['addsize']) {
                    @unlink($newfilename);
                    return -1;
                }
            }
            if (!$upload->get_image_info($newfilename)) {
                @unlink($newfilename);
                return -2;
            }
            require_once libfile('class/image');
            $image = new image();
            $result = $image->Thumb($newfilename, NULL, 140, 140, 1);
            $thumb = empty($result) ? 0 : 1;
            $image->Watermark($newfilename);
            $pic_remote = 0;
            $album_picflag = 1;
            if (getglobal('setting/ftp/on')) {
                $ftpresult_thumb = 0;
                $ftpresult = ftpupload('album/' . $filepath);
                if ($ftpresult) {
                    if ($thumb) {
                        ftpupload('album/' . $filepath . '.thumb.jpg');
                    }
                    $pic_remote = 1;
                    $album_picflag = 2;
                } else {
                    if (getglobal('setting/ftp/mirror')) {
                        @unlink($newfilename);
                        @unlink($newfilename . '.thumb.jpg');
                        return -3;
                    }
                }
            }
            $filename = addslashes($name ? $name : substr(strrchr($filepath, '/'), 1));
            $title = getstr($title, 200, 1, 1, 1);
            if ($albumid) {
                $albumid = album_creat_by_id($albumid);
            } else {
                $albumid = 0;
            }
            $setarr = array('albumid' => $albumid, 'uid' => $_G['uid'], 'username' => $_G['username'], 'dateline' => $_G['timestamp'], 'filename' => $filename, 'postip' => $_G['clientip'], 'title' => $title, 'type' => $fileext, 'size' => $size, 'filepath' => $filepath, 'thumb' => $thumb, 'remote' => $pic_remote);
            $setarr['picid'] = DB::insert('home_pic', $setarr, 1);
            DB::query("UPDATE " . DB::table('common_member_count') . " SET attachsize=attachsize+{$size} WHERE uid='{$_G['uid']}'");
            include_once libfile('function/stat');
            updatestat('pic');
            return $setarr;
        } else {
            fclose($handle);
        }
    }
    return -3;
}
コード例 #2
0
ファイル: forum_ajax.php プロジェクト: vanloswang/DiscuzX
 }
 $content = '';
 if (preg_match('/^(http:\\/\\/|\\.)/i', $imageurl)) {
     $content = dfsockopen($imageurl);
 } elseif (preg_match('/^(' . preg_quote(getglobal('setting/attachurl'), '/') . ')/i', $imageurl)) {
     $imagereplace['newimageurl'][] = $value[0];
 }
 if (empty($content)) {
     continue;
 }
 $patharr = explode('/', $imageurl);
 $attach['name'] = trim($patharr[count($patharr) - 1]);
 $attach['thumb'] = '';
 $attach['isimage'] = $upload->is_image_ext($attach['ext']);
 $attach['extension'] = $upload->get_target_extension($attach['ext']);
 $attach['attachdir'] = $upload->get_target_dir('forum');
 $attach['attachment'] = $attach['attachdir'] . $upload->get_target_filename('forum') . '.' . $attach['extension'];
 $attach['target'] = getglobal('setting/attachdir') . './forum/' . $attach['attachment'];
 if (!@($fp = fopen($attach['target'], 'wb'))) {
     continue;
 } else {
     flock($fp, 2);
     fwrite($fp, $content);
     fclose($fp);
 }
 if (!$upload->get_image_info($attach['target'])) {
     @unlink($attach['target']);
     continue;
 }
 $attach['size'] = filesize($attach['target']);
 $upload->attach = $attach;
コード例 #3
0
ファイル: function_spacecp.php プロジェクト: tianyunchong/php
function stream_save($strdata, $albumid = 0, $fileext = 'jpg', $name = '', $title = '', $delsize = 0, $from = false)
{
    global $_G, $space;
    if ($albumid < 0) {
        $albumid = 0;
    }
    $allowPicType = array('jpg', 'jpeg', 'gif', 'png');
    if (!in_array($fileext, $allowPicType)) {
        return -3;
    }
    $setarr = array();
    $upload = new discuz_upload();
    $filepath = $upload->get_target_dir('album') . $upload->get_target_filename('album') . '.' . $fileext;
    $newfilename = $_G['setting']['attachdir'] . './album/' . $filepath;
    if ($handle = fopen($newfilename, 'wb')) {
        if (fwrite($handle, $strdata) !== FALSE) {
            fclose($handle);
            $size = filesize($newfilename);
            if (empty($space)) {
                $_G['member'] = $space = getuserbyuid($_G['uid']);
                $_G['username'] = $space['username'];
            }
            $_G['member'] = $space;
            loadcache('usergroup_' . $space['groupid']);
            $_G['group'] = $_G['cache']['usergroup_' . $space['groupid']];
            $maxspacesize = checkperm('maxspacesize');
            if ($maxspacesize) {
                space_merge($space, 'count');
                space_merge($space, 'field_home');
                if ($space['attachsize'] + $size - $delsize > $maxspacesize + $space['addsize'] * 1024 * 1024) {
                    @unlink($newfilename);
                    return -1;
                }
            }
            if (!$upload->get_image_info($newfilename)) {
                @unlink($newfilename);
                return -2;
            }
            require_once libfile('class/image');
            $image = new image();
            $result = $image->Thumb($newfilename, NULL, 140, 140, 1);
            $thumb = empty($result) ? 0 : 1;
            $image->Watermark($newfilename);
            $pic_remote = 0;
            $album_picflag = 1;
            if (getglobal('setting/ftp/on')) {
                $ftpresult_thumb = 0;
                $ftpresult = ftpcmd('upload', 'album/' . $filepath);
                if ($ftpresult) {
                    @unlink($_G['setting']['attachdir'] . 'album/' . $filepath);
                    if ($thumb) {
                        $thumbpath = getimgthumbname($filepath);
                        ftpcmd('upload', 'album/' . $thumbpath);
                        @unlink($_G['setting']['attachdir'] . 'album/' . $thumbpath);
                    }
                    $pic_remote = 1;
                    $album_picflag = 2;
                } else {
                    if (getglobal('setting/ftp/mirror')) {
                        @unlink($newfilename);
                        @unlink(getimgthumbname($newfilename));
                        return -3;
                    }
                }
            }
            $filename = $name ? $name : substr(strrchr($filepath, '/'), 1);
            $title = getstr($title, 200);
            $title = censor($title);
            if (censormod($title) || $_G['group']['allowuploadmod']) {
                $pic_status = 1;
            } else {
                $pic_status = 0;
            }
            if ($albumid) {
                $albumid = album_creat_by_id($albumid);
            } else {
                $albumid = 0;
            }
            $setarr = array('albumid' => $albumid, 'uid' => $_G['uid'], 'username' => $_G['username'], 'dateline' => $_G['timestamp'], 'filename' => $filename, 'postip' => $_G['clientip'], 'title' => $title, 'type' => $fileext, 'size' => $size, 'filepath' => $filepath, 'thumb' => $thumb, 'remote' => $pic_remote, 'status' => $pic_status);
            $setarr['picid'] = C::t('home_pic')->insert($setarr, 1);
            C::t('common_member_count')->increase($_G['uid'], array('attachsize' => $size));
            include_once libfile('function/stat');
            updatestat('pic');
            return $setarr;
        } else {
            fclose($handle);
        }
    }
    return -3;
}
コード例 #4
0
 } elseif (checkperm('allowdownlocalimg')) {
     if (preg_match('/^data\\/(.*?)\\.thumb\\.jpg$/i', $imageurl)) {
         $content = file_get_contents(substr($imageurl, 0, strrpos($imageurl, '.') - 6));
     } elseif (preg_match('/^data\\/(.*?)\\.(jpg|jpeg|gif|png)$/i', $imageurl)) {
         $content = file_get_contents($imageurl);
     }
 }
 if (empty($content)) {
     continue;
 }
 $temp = explode('/', $imageurl);
 $attach['name'] = trim($temp[count($temp) - 1]);
 $attach['thumb'] = '';
 $attach['isimage'] = $upload->is_image_ext($attach['ext']);
 $attach['extension'] = $upload->get_target_extension($attach['ext']);
 $attach['attachdir'] = $upload->get_target_dir('portal');
 $attach['attachment'] = $attach['attachdir'] . $upload->get_target_filename('portal') . '.' . $attach['extension'];
 $attach['target'] = getglobal('setting/attachdir') . './portal/' . $attach['attachment'];
 if (!@($fp = fopen($attach['target'], 'wb'))) {
     continue;
 } else {
     flock($fp, 2);
     fwrite($fp, $content);
     fclose($fp);
 }
 if (!$upload->get_image_info($attach['target'])) {
     @unlink($attach['target']);
     continue;
 }
 $attach['size'] = filesize($attach['target']);
 $attachs[] = daddslashes($attach);
コード例 #5
0
ファイル: function.article.php プロジェクト: edmundwong/V604
function forum_downremotefile($arr, $old_arr)
{
    global $_G;
    $evo_img_no = $_G['cache']['evn_milu_pick']['evo_img_no'];
    $config = get_pick_set();
    $get_file_ext_arr = $config['get_file_ext'] ? explode('|', $config['get_file_ext']) : array();
    $arr['is_download_file'] = $arr['is_download_file'] ? $arr['is_download_file'] : $arr['p_arr']['is_download_file'];
    $arr['message'] = dstripslashes($arr['content']);
    //print_r($arr);
    //$arr['message'] = str_replace(array("\r", "\n"), array($_GET['wysiwyg'] ? '<br />' : '', "\\n"), $arr['message']);
    preg_match_all("/\\[img\\]\\s*([^\\[\\<\r\n]+?)\\s*\\[\\/img\\]|\\[img=\\d{1,4}[x|\\,]\\d{1,4}\\]\\s*([^\\[\\<\r\n]+?)\\s*\\[\\/img\\]/is", $arr['message'], $image1, PREG_SET_ORDER);
    //preg_match_all("/\<img.+src=('|\"|)?(.*)(\\1)([\s].*)?\>/ismUe", $arr['message'], $image2, PREG_SET_ORDER);
    preg_match_all("/\\<img.+src=('|\"|)?(.*)(\\1)(.*)?\\>/isU", $arr['message'], $image2, PREG_SET_ORDER);
    $temp = $aids = $existentimg = $attach_arr = array();
    if (is_array($image1) && !empty($image1)) {
        foreach ($image1 as $value) {
            $v = trim(!empty($value[1]) ? $value[1] : $value[2]);
            $no_remote = 0;
            if (!filter_something($v, $evo_img_no)) {
                //存在
                $no_remote = 1;
            }
            if ($no_remote == 0) {
                $temp[] = array('0' => $value[0], '1' => $v);
            }
        }
    }
    if (is_array($image2) && !empty($image2)) {
        foreach ($image2 as $v) {
            $no_remote = 0;
            $v[2] = trim(strip_tags($v[2]));
            if (!filter_something($v[2], $evo_img_no)) {
                //存在
                $no_remote = 1;
            }
            if ($no_remote == 0) {
                $temp[] = array('0' => $v[0], '1' => $v[2]);
            }
        }
    }
    if ($arr['is_download_file'] == 1) {
        $attach_arr = get_attach_data($arr['page_url'], $arr['message']);
    }
    $attach_arr = $attach_arr ? $attach_arr : array();
    $temp = $temp ? $temp : array();
    $temp = array_merge($temp, $attach_arr);
    //if(VIP) $arr['message'] = post($arr['message'], array('cookie' => $arr['cookie'], 'page_url' => $arr['page_url'], 'cid' => $arr['cid']));
    $del_a = 0;
    if ($arr['content_filter_html'][0] == 0 && $arr['content_filter_html']) {
        $del_a = 1;
    }
    //print_r($arr['message']);exit();
    require_once libfile('class/image');
    if (is_array($temp) && !empty($temp)) {
        if (file_exists(libfile('class/upload'))) {
            require_once libfile('class/upload');
        } else {
            require_once libfile('discuz/upload', 'class');
        }
        $upload = new discuz_upload();
        $attachaids = array();
        $threadimage_flag = 0;
        $content_md5_arr = array();
        foreach ($temp as $key => $value) {
            $snoopy_args['cookie'] = $arr['cookie'];
            $snoop_obj = get_snoopy_obj($snoopy_args);
            $imageurl = $value[1];
            $hash = md5($imageurl);
            if (strlen($imageurl)) {
                $imagereplace['oldimageurl'][] = $value[0];
                if (!isset($existentimg[$hash])) {
                    $existentimg[$hash] = $imageurl;
                    $attach['ext'] = $upload->fileext($imageurl);
                    if ($upload->is_image_ext($attach['ext']) == 1 && $arr['is_download_img'] != 1) {
                        $imagereplace['newimageurl'][] = $value[0];
                        continue;
                    }
                    if (!$upload->is_image_ext($attach['ext'])) {
                        $ext = 'no_get';
                    }
                    if (preg_match('/^(http:\\/\\/|\\.)/i', $imageurl)) {
                        if ($imageurl && snoop_obj) {
                            $content_re = get_img_content($imageurl, $snoop_obj, $ext);
                        }
                        if (is_array($content_re)) {
                            $content = $content_re['content'];
                            $file_name = $attach['name'] = $content_re['file_name'] ? $content_re['file_name'] : ($value[2] ? _striptext($value[2]) : time() . '.' . $content_re['file_ext']);
                            $attach['ext'] = $content_re['file_ext'] ? $content_re['file_ext'] : trim($upload->fileext($file_name));
                            $file_name = $attach['name'] = $file_name;
                        } else {
                            $content = $content_re;
                        }
                        if (in_array(md5($content), $content_md5_arr)) {
                            $imagereplace['newimageurl'][] = '';
                            continue;
                        }
                        $content_md5_arr[] = md5($content);
                    } elseif (preg_match('/^(' . preg_quote(getglobal('setting/attachurl'), '/') . ')/i', $imageurl)) {
                        $imagereplace['newimageurl'][] = $value[0];
                    }
                    if (empty($content)) {
                        if ($value[4] == 1) {
                            if ($del_a == 1) {
                                $imagereplace['newimageurl'][] = $value[2];
                            } else {
                                unset($imagereplace['oldimageurl'][$key]);
                            }
                        } else {
                            $imagereplace['newimageurl'][] = '';
                        }
                        continue;
                    }
                    if (!$attach['name']) {
                        $patharr = explode('/', $imageurl);
                        $attach['name'] = trim($patharr[count($patharr) - 1]);
                    }
                    $patharr = explode('/', $imageurl);
                    if (!$attach['name']) {
                        $attach['name'] = trim($patharr[count($patharr) - 1]);
                    }
                    $attach['thumb'] = '';
                    $attach['ext'] = trim($attach['ext']);
                    //不加这个有些还真不行
                    $attach['isimage'] = $upload->is_image_ext($attach['ext']);
                    if ($attach['isimage'] == 1 && $arr['is_download_img'] != 1) {
                        $imagereplace['newimageurl'][] = $value[0];
                        continue;
                    }
                    $attach['extension'] = $upload->get_target_extension($attach['ext']);
                    $attach['attachdir'] = $upload->get_target_dir('forum');
                    $attach['attachment'] = $attach['attachdir'] . $upload->get_target_filename('forum') . '.' . $attach['extension'];
                    $attach['target'] = getglobal('setting/attachdir') . './forum/' . $attach['attachment'];
                    if (!in_array($attach['ext'], $get_file_ext_arr) && $get_file_ext_arr && $attach['isimage'] == 0) {
                        if ($value[4] == 1) {
                            if ($del_a == 1) {
                                $imagereplace['newimageurl'][] = $value[2];
                            } else {
                                unset($imagereplace['oldimageurl'][$key]);
                            }
                        } else {
                            $imagereplace['newimageurl'][] = '';
                        }
                        continue;
                    }
                    if (!@($fp = fopen($attach['target'], 'wb'))) {
                        continue;
                    } else {
                        flock($fp, 2);
                        fwrite($fp, $content);
                        fclose($fp);
                    }
                    if (!$upload->get_image_info($attach['target']) && $attach['isimage'] == 1) {
                        @unlink($attach['target']);
                        continue;
                    }
                    $attach['size'] = filesize($attach['target']);
                    $upload->attach = $attach;
                    $thumb = $width = 0;
                    if ($upload->attach['isimage']) {
                        if ($_G['setting']['thumbstatus']) {
                            $image = new image();
                            $thumb = $image->Thumb($upload->attach['target'], '', $_G['setting']['thumbwidth'], $_G['setting']['thumbheight'], $_G['setting']['thumbstatus'], $_G['setting']['thumbsource']) ? 1 : 0;
                            $width = $image->imginfo['width'];
                        }
                        if ($_G['setting']['thumbsource'] || !$_G['setting']['thumbstatus']) {
                            list($width) = @getimagesize($upload->attach['target']);
                        }
                        if ($_G['setting']['watermarkstatus'] && empty($_G['forum']['disablewatermark']) && $arr['is_water_img'] == 1) {
                            $image = new image();
                            $image->Watermark($attach['target'], '', 'forum');
                        }
                    }
                    $desc = $value[3];
                    $arr['public_time'] = $arr['public_time'] ? $arr['public_time'] : $arr['dateline'];
                    $arr['public_time'] = $arr['public_time'] ? $arr['public_time'] : $_G['timestamp'];
                    $remote = 0;
                    $setarr = array('uid' => $arr['uid'], 'tid' => $arr['tid'], 'pid' => $arr['pid'], 'filename' => daddslashes($upload->attach['name']), 'attachment' => $upload->attach['attachment'], 'filesize' => $upload->attach['size'], 'thumb' => $thumb, 'remote' => $remote, 'picid' => $picid, 'isimage' => $attach['isimage'], 'description' => $desc, 'readperm' => 0, 'price' => 0, 'width' => $width, 'dateline' => $arr['public_time']);
                    $setimg_arr = array('tid' => $arr['tid'], 'attachment' => $upload->attach['attachment'], 'remote' => $remote);
                    $set_att = array('downloads' => rand(1, 15), 'tableid' => getattachtableid($arr['tid']), 'uid' => $arr['uid'], 'pid' => $arr['pid'], 'tid' => $arr['tid']);
                    if ($threadimage_flag == 0 && !$arr['is_post'] && $attach['isimage'] == 1) {
                        DB::insert('forum_threadimage', $setimg_arr, true);
                        $threadimage_flag = 1;
                    }
                    $setarr['aid'] = $newaids[] = DB::insert('forum_attachment', $set_att, true);
                    $at[] = $setarr['aid'];
                    $attachnew_arr[$setarr['aid']] = array('description' => $setarr['description']);
                    DB::insert(getattachtablebytid($arr['tid']), $setarr, true);
                    $attachaids[$hash] = $imagereplace['newimageurl'][] = '[attach]' . $setarr['aid'] . '[/attach]';
                } else {
                    $imagereplace['newimageurl'][] = $attachaids[$hash];
                }
            }
        }
        if ($_G['setting']['ftp']['on'] == 1) {
            require_once libfile('function/post');
            ftpupload($newaids, $arr['uid']);
        }
        if (count($at) > 0) {
            $arr['attachment'] = 2;
        }
        $arr['message'] = str_replace($imagereplace['oldimageurl'], $imagereplace['newimageurl'], $arr['message']);
        if ($del_a == 1) {
            $arr['message'] = clear_html_script($arr['message'], array(0));
        }
        forum_article_content($arr);
    }
}
コード例 #6
0
ファイル: cut_pic.php プロジェクト: Mushan3420/BigApp-PHP7
 * 目前支持GD库和imagick
 * @author zhengtao
 * @param 2015 05 07
 */
$allow_pic_array = array("20_20" => array(20, 20), "30_30" => array(30, 30), "40_40" => array(40, 40), "60_60" => array(60, 60), "80_80" => array(80, 80), "88_88" => array(88, 88), "96_96" => array(96, 96), "100_100" => array(100, 100), "200_200" => array(200, 200), "300_300" => array(300, 300), "400_400" => array(400, 400), "500_500" => array(500, 500), "600_600" => array(600, 600), "700_700" => array(700, 700), "750_342" => array(750, 342), "800_800" => array(800, 800), "900_900" => array(900, 900), "1000_1000" => array(1000, 1000), "1024_1024" => array(1024, 1024), "1242_2208" => array(1242, 2208));
$hashlevel = 3;
//保存的图片的层级
$thisdir = dirname(__FILE__);
$default_pic = $thisdir . "/Image/default.png";
//默认图片的地址
$pic_url = isset($_GET['url']) ? $_GET['url'] : "";
$raw_pic_url = $pic_url;
$pic_size = isset($_GET['size']) ? $_GET['size'] : "";
$log_file = $thisdir . '/' . date("Y-m-d") . ".log";
$dzUp = new discuz_upload();
$dir2 = $dzUp->get_target_dir('common', strlen($pic_url));
$url_pathinfo = pathinfo($pic_url);
if (empty($url_pathinfo['extension'])) {
    $url_pathinfo['extension'] = 'png';
}
//判断是否是非法后缀,非法后缀则直接跳转
if (!isValidExt($pic_url)) {
    runlog('bigapp', 'invalid postfix, reject to optmize, just redirect [ url: ' . $pic_url . ' ]');
    redirect($pic_url);
}
$dir = getglobal('setting/attachdir') . './common/' . $dir2 . 'bigapp/';
//图片存储的目录
if ($pic_url != "" && array_key_exists($pic_size, $allow_pic_array)) {
    $size = $pic_size;
    $url_md5 = md5($pic_url);
    for ($i = 0; $i < $hashlevel; $i++) {