Ejemplo n.º 1
0
function DoCropImage($add, $userid, $username)
{
    global $empire, $dbtbpre, $public_r, $class_r, $ecms_config, $efileftp_fr, $efileftp_dr;
    //参数处理
    $pic_x = (int) $add['pic_x'];
    $pic_y = (int) $add['pic_y'];
    $pic_w = (int) $add['pic_w'];
    $pic_h = (int) $add['pic_h'];
    $doing = (int) $add['doing'];
    $fileid = (int) $add['fileid'];
    $filepass = (int) $add['filepass'];
    $classid = (int) $add['classid'];
    $infoid = (int) $add['infoid'];
    $modtype = (int) $add['modtype'];
    $fstb = 0;
    if (empty($modtype)) {
        $fstb = GetInfoTranFstb($classid, $infoid, 0);
    }
    //取得文件地址
    if (empty($fileid)) {
        printerror('NotCropImage', 'history.go(-1)');
    }
    $filer = $empire->fetch1("select fileid,path,filename,classid,fpath,no from " . eReturnFileTable($modtype, $fstb) . " where fileid='{$fileid}'");
    if (empty($filer['fileid'])) {
        printerror('NotCropImage', 'history.go(-1)');
    }
    $path = $filer['path'] ? $filer['path'] . '/' : $filer['path'];
    $fspath = ReturnFileSavePath($filer['classid'], $filer['fpath']);
    $big_image_name = eReturnEcmsMainPortPath() . $fspath['filepath'] . $path . $filer['filename'];
    //moreport
    if (!file_exists($big_image_name)) {
        printerror('NotCropImage', 'history.go(-1)');
    }
    $filetype = GetFiletype($filer['filename']);
    //取得文件类型
    if (!strstr($ecms_config['sets']['tranpicturetype'], ',' . $filetype . ',')) {
        printerror('CropImageFiletypeFail', 'history.go(-1)');
    }
    //目标图片
    $new_datepath = FormatFilePath($filer['classid'], '', 0);
    $new_path = $new_datepath ? $new_datepath . '/' : $new_datepath;
    $new_insertfile = ReturnDoTranFilename($filer['filename'], 0);
    $new_fspath = ReturnFileSavePath($filer['classid']);
    $new_savepath = eReturnEcmsMainPortPath() . $new_fspath['filepath'] . $new_path;
    //moreport
    $new_name = $new_savepath . $new_insertfile;
    //处理图片
    $returnr['file'] = '';
    $returnr['filetype'] = '';
    if ($temp_img_type = @getimagesize($big_image_name)) {
        preg_match('/\\/([a-z]+)$/i', $temp_img_type[mime], $tpn);
        $img_type = $tpn[1];
    } else {
        preg_match('/\\.([a-z]+)$/i', $big_image_name, $tpn);
        $img_type = $tpn[1];
    }
    $all_type = array("jpg" => array("create" => "ImageCreateFromjpeg", "output" => "imagejpeg", "exn" => ".jpg"), "gif" => array("create" => "ImageCreateFromGIF", "output" => "imagegif", "exn" => ".gif"), "jpeg" => array("create" => "ImageCreateFromjpeg", "output" => "imagejpeg", "exn" => ".jpg"), "png" => array("create" => "imagecreatefrompng", "output" => "imagepng", "exn" => ".png"), "wbmp" => array("create" => "imagecreatefromwbmp", "output" => "image2wbmp", "exn" => ".wbmp"));
    $func_create = $all_type[$img_type]['create'];
    if (empty($func_create) or !function_exists($func_create)) {
        printerror('CropImageFiletypeFail', 'history.go(-1)');
    }
    //输出
    $func_output = $all_type[$img_type]['output'];
    $func_exname = $all_type[$img_type]['exn'];
    if (($func_exname == '.gif' || $func_exname == '.png' || $func_exname == '.wbmp') && !function_exists($func_output)) {
        $func_output = 'imagejpeg';
        $func_exname = '.jpg';
    }
    $big_image = $func_create($big_image_name);
    $big_width = imagesx($big_image);
    $big_height = imagesy($big_image);
    if (!$big_width || !$big_height || $big_width < 10 || $big_height < 10) {
        printerror('CropImageFilesizeFail', 'history.go(-1)');
    }
    if (function_exists("imagecopyresampled")) {
        $temp_image = imagecreatetruecolor($pic_w, $pic_h);
        imagecopyresampled($temp_image, $big_image, 0, 0, $pic_x, $pic_y, $pic_w, $pic_h, $pic_w, $pic_h);
    } else {
        $temp_image = imagecreate($pic_w, $pic_h);
        imagecopyresized($temp_image, $big_image, 0, 0, $pic_x, $pic_y, $pic_w, $pic_h, $pic_w, $pic_h);
    }
    $func_output($temp_image, $new_name . $func_exname);
    ImageDestroy($big_image);
    ImageDestroy($temp_image);
    $insert_file = $new_name . $func_exname;
    $insert_filename = $new_insertfile . $func_exname;
    if (file_exists($insert_file)) {
        if (!$doing) {
            $empire->query("delete from " . eReturnFileTable($modtype, $fstb) . " where fileid='{$fileid}'");
            DelFiletext($big_image_name);
            //FileServer
            if ($public_r['openfileserver']) {
                $efileftp_dr[] = $big_image_name;
            }
        }
        //写入数据库
        $no = '[CropImg]' . $filer['no'];
        $filesize = filesize($insert_file);
        $filesize = (int) $filesize;
        $classid = (int) $classid;
        $type = 1;
        eInsertFileTable($insert_filename, $filesize, $new_datepath, $username, $classid, $no, $type, $filepass, $filepass, $public_r[fpath], 0, $modtype, $fstb);
        //FileServer
        if ($public_r['openfileserver']) {
            $efileftp_fr[] = $insert_file;
        }
    }
    echo "<script>opener.ReloadChangeFilePage();window.close();</script>";
    db_close();
    exit;
}
Ejemplo n.º 2
0
function DoTranUrl($url, $classid)
{
    global $public_r, $class_r, $ecms_config, $efileftp_fr;
    $classid = (int) $classid;
    //处理地址
    $url = trim($url);
    $url = str_replace(" ", "%20", $url);
    $r[tran] = 1;
    //附件地址
    $r[url] = $url;
    //文件类型
    $r[filetype] = GetFiletype($url);
    if (CheckSaveTranFiletype($r[filetype])) {
        $r[tran] = 0;
        return $r;
    }
    //是否已上传的文件
    $havetr = CheckNotSaveUrl($url);
    if ($havetr) {
        $r[tran] = 0;
        return $r;
    }
    //是否地址
    if (!strstr($url, '://')) {
        $r[tran] = 0;
        return $r;
    }
    $string = ReadFiletext($url);
    if (empty($string)) {
        $r[tran] = 0;
        return $r;
    }
    //文件名
    $r[insertfile] = ReturnDoTranFilename($file_name, $classid);
    $r[filename] = $r[insertfile] . $r[filetype];
    //日期目录
    $r[filepath] = FormatFilePath($classid, $mynewspath, 0);
    $filepath = $r[filepath] ? $r[filepath] . '/' : $r[filepath];
    //存放目录
    $fspath = ReturnFileSavePath($classid);
    $r[savepath] = eReturnEcmsMainPortPath() . $fspath['filepath'] . $filepath;
    //moreport
    //附件地址
    $r[url] = $fspath['fileurl'] . $filepath . $r[filename];
    //缩图文件
    $r[name] = $r[savepath] . "small" . $r[insertfile];
    //附件文件
    $r[yname] = $r[savepath] . $r[filename];
    WriteFiletext_n($r[yname], $string);
    $r[filesize] = @filesize($r[yname]);
    //返回类型
    if (strstr($ecms_config['sets']['tranflashtype'], ',' . $r[filetype] . ',')) {
        $r[type] = 2;
    } elseif (strstr($ecms_config['sets']['tranpicturetype'], ',' . $r[filetype] . ',')) {
        $r[type] = 1;
    } elseif (strstr($ecms_config['sets']['mediaplayertype'], ',' . $r[filetype] . ',') || strstr($ecms_config['sets']['realplayertype'], ',' . $r[filetype] . ',')) {
        $r[type] = 3;
    } else {
        $r[type] = 0;
    }
    //FileServer
    if ($public_r['openfileserver']) {
        $efileftp_fr[] = $r['yname'];
    }
    return $r;
}