Пример #1
0
function read_dir_pic($main_dir = "")
{
    global $xoopsDB;
    $pics = "";
    $post_max_size = ini_get('post_max_size');
    //$size_limit=intval($post_max_size) * 0.5  * 1024 * 1024;
    if (substr($main_dir, -1) != '/') {
        $main_dir = $main_dir . "/";
    }
    if ($dh = opendir($main_dir)) {
        $total_size = 0;
        $i = 1;
        while (($file = readdir($dh)) !== false) {
            if (substr($file, 0, 1) == ".") {
                continue;
            }
            if (is_dir($main_dir . $file)) {
                $pic = read_dir_pic($main_dir . $file);
                $pics .= $pic['pics'];
                $total_size += $pic['total_size'];
            } else {
                //讀取exif資訊
                $result = exif_read_data($main_dir . $file, 0, true);
                $creat_date = $result['IFD0']['DateTime'];
                $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);
                $size = filesize($main_dir . $file);
                $total_size += intval($size);
                $size_txt = sizef($size);
                $pic = getimagesize($main_dir . $file);
                $width = $pic[0];
                $height = $pic[1];
                $subname = strtolower(substr($file, -3));
                if ($subname == "jpg" or $subname == "peg") {
                    $type = "image/jpeg";
                } elseif ($subname == "png") {
                    $type = "image/png";
                } elseif ($subname == "gif") {
                    $type = "image/gif";
                } else {
                    $type = $subname;
                    continue;
                }
                $sql = "select width,height from " . $xoopsDB->prefix("tad_gallery") . " where filename='{$file}' and size='{$size}'";
                $result = $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'], 3, mysql_error());
                list($db_width, $db_height) = $xoopsDB->fetchRow($result);
                if ($db_width == $width and $db_height == $height) {
                    $checked = "disabled='disabled'";
                    $upload = "0";
                    $status = _MD_TADGAL_IMPORT_EXIST;
                    //}elseif($total_size >= $size_limit){
                    // $checked="disabled='disabled'";
                    // $upload="1";
                    // $status=sprintf(_MD_TADGAL_IMPORT_OVER_SIZE,sizef($total_size),$post_max_size);
                } else {
                    $checked = "checked='checked'";
                    $upload = "1";
                    $status = $type;
                }
                if (_CHARSET == "UTF-8") {
                    $file = to_utf8($file);
                }
                $pics .= "\n                <tr>\n                  <td style='font-size:11px'>{$i}</td>\n                  <td style='font-size:11px'>\n                    <input type='hidden' name='all[{$i}]' value='" . $main_dir . $file . "'>\n                    <input type='checkbox' name='import[{$i}][upload]' value='1' {$checked}>\n                    {$file}\n                    <input type='hidden' name='import[{$i}][filename]' value='{$file}'></td>\n                  <td style='font-size:11px'>{$dir}<input type='hidden' name='import[{$i}][dir]' value='{$dir}'></td>\n                  <td style='font-size:11px'>{$width} x {$height}\n                    <input type='hidden' name='import[{$i}][post_date]' value='{$creat_date}'>\n                    <input type='hidden' name='import[{$i}][width]' value='{$width}'>\n                    <input type='hidden' name='import[{$i}][height]' value='{$height}'></td>\n                  <td style='font-size:11px'>{$size_txt}<input type='hidden' name='import[{$i}][size]' value='{$size}'></td>\n                  <td style='font-size:11px'>{$status}\n                    <input type='hidden' name='import[{$i}][exif]' value='{$exif}'>\n                    <input type='hidden' name='import[{$i}][type]' value='{$type}'></td>\n                </tr>";
                $i++;
            }
        }
        closedir($dh);
    }
    $main['pics'] = $pics;
    $main['total_size'] = $total_size;
    return $main;
}
Пример #2
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;
}