Exemplo n.º 1
0
function upload_muti_file()
{
    global $xoopsDB, $xoopsUser, $xoopsModule, $xoopsModuleConfig, $type_to_mime;
    krsort($_POST['csn_menu']);
    foreach ($_POST['csn_menu'] as $cate_sn) {
        if (empty($cate_sn)) {
            continue;
        } else {
            $csn = $cate_sn;
            break;
        }
    }
    if (!empty($_POST['new_csn'])) {
        $csn = add_tad_gallery_cate($csn, $_POST['new_csn'], $_POST['sort']);
    }
    $uid = $xoopsUser->getVar('uid');
    if (!empty($_POST['csn'])) {
        $_SESSION['tad_gallery_csn'] = $_POST['csn'];
    }
    //取消上傳時間限制
    set_time_limit(0);
    //設置上傳大小
    ini_set('memory_limit', '100M');
    $files = array();
    foreach ($_FILES['upfile'] as $k => $l) {
        foreach ($l as $i => $v) {
            if (empty($v)) {
                continue;
            }
            if (!array_key_exists($i, $files)) {
                $files[$i] = array();
            }
            $files[$i][$k] = $v;
        }
    }
    $sort = 0;
    foreach ($files as $i => $file) {
        if (empty($file['tmp_name'])) {
            continue;
        }
        $orginal_file_name = strtolower(basename($file["name"]));
        //get lowercase filename
        $file_ending = substr(strtolower($orginal_file_name), -3);
        //file extension
        $pic = getimagesize($file['tmp_name']);
        $width = $pic[0];
        $height = $pic[1];
        //讀取exif資訊
        if (function_exists('exif_read_data')) {
            $result = exif_read_data($file['tmp_name'], 0, true);
            $creat_date = $result['IFD0']['DateTime'];
        } else {
            $creat_date = date("Y-m-d");
        }
        $dir = (empty($creat_date) or substr($creat_date, 0, 1) != "2") ? date("Y_m_d") : str_replace(":", "_", substr($result['IFD0']['DateTime'], 0, 10));
        $exif = mk_exif($result);
        $now = date("Y-m-d H:i:s", xoops_getUserTimestamp(time()));
        $sql = "insert into " . $xoopsDB->prefix("tad_gallery") . "\n        (`csn`, `title`, `description`, `filename`, `size`, `type`, `width`, `height`, `dir`, `uid`, `post_date`, `counter`, `exif`, `tag`, `good`, `photo_sort`)\n        values('{$csn}','','','{$file['name']}','{$file['size']}','{$file['type']}','{$width}','{$height}','{$dir}','{$uid}','{$now}','0','{$exif}','','0',{$sort})";
        $sort++;
        $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'], 10, mysql_error() . $sql);
        //取得最後新增資料的流水編號
        $sn = $xoopsDB->getInsertId();
        mk_dir(_TADGAL_UP_FILE_DIR . $dir);
        mk_dir(_TADGAL_UP_FILE_DIR . "small/" . $dir);
        mk_dir(_TADGAL_UP_FILE_DIR . "medium/" . $dir);
        $filename = photo_name($sn, "source", 1);
        if (move_uploaded_file($file['tmp_name'], $filename)) {
            $m_thumb_name = photo_name($sn, "m", 1);
            $s_thumb_name = photo_name($sn, "s", 1);
            if (!empty($xoopsModuleConfig['thumbnail_b_width']) and ($width > $xoopsModuleConfig['thumbnail_b_width'] or $height > $xoopsModuleConfig['thumbnail_b_width'])) {
                thumbnail($filename, $filename, $type_to_mime[$file_ending], $xoopsModuleConfig['thumbnail_b_width']);
            }
            if ($width > $xoopsModuleConfig['thumbnail_m_width'] or $height > $xoopsModuleConfig['thumbnail_m_width']) {
                thumbnail($filename, $m_thumb_name, $type_to_mime[$file_ending], $xoopsModuleConfig['thumbnail_m_width']);
            }
            if ($width > $xoopsModuleConfig['thumbnail_s_width'] or $height > $xoopsModuleConfig['thumbnail_s_width']) {
                thumbnail($filename, $s_thumb_name, $type_to_mime[$file_ending], $xoopsModuleConfig['thumbnail_s_width']);
            }
        }
    }
    return $csn;
}
Exemplo n.º 2
0
function import_tad_gallery($csn_menu = array(), $new_csn = "", $all = array(), $import = array())
{
    global $xoopsDB, $xoopsUser, $xoopsModuleConfig, $type_to_mime;
    krsort($csn_menu);
    foreach ($csn_menu as $cate_sn) {
        if (empty($cate_sn)) {
            continue;
        } else {
            $csn = $cate_sn;
            break;
        }
    }
    if (!empty($new_csn)) {
        $csn = add_tad_gallery_cate($csn, $new_csn);
    }
    $uid = $xoopsUser->getVar('uid');
    if (!empty($csn)) {
        $_SESSION['tad_gallery_csn'] = $csn;
    }
    //處理上傳的檔案
    $sort = 0;
    foreach ($all as $i => $source_file) {
        if ($import[$i]['upload'] != '1') {
            unlink($source_file);
            continue;
        }
        $orginal_file_name = strtolower(basename($import[$i]['filename']));
        //get lowercase filename
        $file_ending = substr(strtolower($orginal_file_name), -3);
        //file extension
        $sql = "insert into " . $xoopsDB->prefix("tad_gallery") . " (\n      `csn`, `title`, `description`, `filename`, `size`, `type`, `width`, `height`, `dir`, `uid`, `post_date`, `counter`, `exif`, `tag`, `good`, `photo_sort`) values('{$csn}','','','{$import[$i]['filename']}','{$import[$i]['size']}','{$import[$i]['type']}','{$import[$i]['width']}','{$import[$i]['height']}','{$import[$i]['dir']}','{$uid}','{$import[$i]['post_date']}','0','{$import[$i]['exif']}','','0',{$sort})";
        $sort++;
        $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'], 10, mysql_error() . $sql);
        //取得最後新增資料的流水編號
        $sn = $xoopsDB->getInsertId();
        set_time_limit(0);
        mk_dir(_TADGAL_UP_FILE_DIR . $import[$i]['dir']);
        mk_dir(_TADGAL_UP_FILE_DIR . "small/" . $import[$i]['dir']);
        mk_dir(_TADGAL_UP_FILE_DIR . "medium/" . $import[$i]['dir']);
        $filename = photo_name($sn, "source", 1);
        if (rename($source_file, $filename)) {
            $m_thumb_name = photo_name($sn, "m", 1);
            $s_thumb_name = photo_name($sn, "s", 1);
            if (!empty($xoopsModuleConfig['thumbnail_b_width']) and ($import[$i]['width'] > $xoopsModuleConfig['thumbnail_b_width'] or $import[$i]['height'] > $xoopsModuleConfig['thumbnail_b_width'])) {
                thumbnail($filename, $filename, $type_to_mime[$file_ending], $xoopsModuleConfig['thumbnail_b_width']);
            }
            if ($import[$i]['width'] > $xoopsModuleConfig['thumbnail_m_width'] or $import[$i]['height'] > $xoopsModuleConfig['thumbnail_m_width']) {
                thumbnail($filename, $m_thumb_name, $type_to_mime[$file_ending], $xoopsModuleConfig['thumbnail_m_width']);
            }
            if ($import[$i]['width'] > $xoopsModuleConfig['thumbnail_s_width'] or $import[$i]['height'] > $xoopsModuleConfig['thumbnail_s_width']) {
                thumbnail($filename, $s_thumb_name, $type_to_mime[$file_ending], $xoopsModuleConfig['thumbnail_s_width']);
            }
        } else {
            $sql = "delete from " . $xoopsDB->prefix("tad_gallery") . " where sn='{$sn}'";
            $xoopsDB->query($sql);
            redirect_header($_SERVER['PHP_SELF'], 5, sprintf(_MD_TADGAL_IMPORT_IMPORT_ERROR, $source_file, $filename));
        }
    }
    rrmdir(_TADGAL_UP_IMPORT_DIR);
    return $csn;
}
Exemplo n.º 3
0
function update_tad_gallery($sn = "")
{
    global $xoopsDB, $xoopsUser;
    krsort($_POST['csn_menu']);
    foreach ($_POST['csn_menu'] as $cate_sn) {
        if (empty($cate_sn)) {
            continue;
        } else {
            $csn = $cate_sn;
            break;
        }
    }
    if (!empty($_POST['new_csn'])) {
        $csn = add_tad_gallery_cate($csn, $_POST['new_csn'], $_POST['sort']);
    }
    $uid = $xoopsUser->getVar('uid');
    if (!empty($_POST['csn'])) {
        $_SESSION['tad_gallery_csn'] = $_POST['csn'];
    }
    $myts =& MyTextSanitizer::getInstance();
    $title = $myts->addSlashes($_POST['title']);
    $description = $myts->addSlashes($_POST['description']);
    $new_tag = $myts->addSlashes($_POST['new_tag']);
    $all_tag = implode(",", $_POST['tag']);
    if (!empty($new_tag)) {
        $new_tags = explode(",", $new_tag);
    }
    foreach ($new_tags as $tag) {
        if (!empty($tag)) {
            $tag = trim($tag);
            $all_tag .= ",{$tag}";
        }
    }
    $sql = "update " . $xoopsDB->prefix("tad_gallery") . " set `csn`='{$csn}',`title`='{$title}',`description`='{$description}',`tag`='{$all_tag}' where sn='{$sn}'";
    $xoopsDB->queryF($sql) or redirect_header($_SERVER['PHP_SELF'], 10, mysql_error());
    //設為封面
    if (!empty($_POST['cover'])) {
        $sql = "update " . $xoopsDB->prefix("tad_gallery_cate") . " set `cover`='{$_POST['cover']}' where csn='{$csn}'";
        $xoopsDB->queryF($sql) or redirect_header($_SERVER['PHP_SELF'], 10, mysql_error());
    }
}