예제 #1
0
            $attachment = 1;
        }
    } else {
        $attachment = 0;
    }
    C::t('forum_thread')->update($tid, array('attachment' => $attachment));
    C::t('forum_post')->update('tid:' . $tid, $pid, array('attachment' => $attachment), true);
    if (!$attachment) {
        C::t('forum_threadimage')->delete_by_tid($tid);
    }
    if ($cover) {
        $basedir = DISCUZ_ROOT . './data/attachment/';
        $coverdir = 'threadcover/' . substr(md5($tid), 0, 2) . '/' . substr(md5($tid), 2, 2) . '/';
        dmkdir($basedir . './forum/' . $coverdir);
        $covername = $path . $coverdir . $tid . '.jpg';
        cut_pic($path . $attachments, $covername);
    }
    $cover_num = 0;
    $cover_num = C::t('forum_attachment_n')->count_image_by_id('tid:' . $tid, 'pid', $pid);
    C::t('forum_thread')->update($tid, array('cover' => $cover_num));
    $res['aid'] = $aid;
    $res['err'] = 0;
}
function cut_pic($src_img, $filename)
{
    list($src_w, $src_h) = getimagesize($src_img);
    // 获取原图尺寸
    $dst_h = 580;
    $dst_w = 580;
    $dst_scale = $dst_h / $dst_w;
    //目标图像长宽比
예제 #2
0
<?php

if (isset($_FILES['fileField'])) {
    move_uploaded_file($_FILES["fileField"]["tmp_name"], $_FILES["fileField"]["name"]);
    echo 'ok';
} else {
    echo 'not found field:[fileField]';
}
cut_pic($_FILES["fileField"]["name"], 'a11.jpg');
function cut_pic($src_img, $filename)
{
    list($src_w, $src_h) = getimagesize($src_img);
    // 获取原图尺寸
    $dst_h = 580;
    $dst_w = 580;
    $dst_scale = $dst_h / $dst_w;
    //目标图像长宽比
    $src_scale = $src_h / $src_w;
    // 原图长宽比
    if ($src_scale >= $dst_scale) {
        // 过高
        $w = intval($src_w);
        $h = intval($dst_scale * $w);
        $x = 0;
        $y = ($src_h - $h) / 3;
    } else {
        // 过宽
        $h = intval($src_h);
        $w = intval($h / $dst_scale);
        $x = ($src_w - $w) / 2;
        $y = 0;