Пример #1
0
 $savedir = date('ym');
 //保存路径
 $attachdir = 'upload/' . $savedir . '/';
 //文件上传路径
 //$fileuplodeurl= $savedir.'/'.$fileuplodeurl;
 //如果文件夹不存在,则建立文件夹
 if (!is_dir($attachdir)) {
     @mkdir($attachdir);
     @chmod($attachdir, 0777);
     @fclose(@fopen($attachdir . '/index.html', 'w'));
     @chmod($attachdir . '/index.html', 0777);
 }
 $source = $attachdir . $fileuplodeurl;
 //版块id_文件名_时间.类型
 //DebugStr($savedir);
 if (!postupload($atc_attachment, $source)) {
     DebugStr('文件上传失败!');
 }
 //判断文件类型
 $type = 'img';
 /**/
 //获取文件大小
 $size = ceil(filesize("{$attachdir}/{$fileuplodeurl}") / 1024);
 $atc_attachment_name = addslashes($atc_attachment_name);
 $ArrField = array('fid', 'uid', 'hits', 'name', 'type', 'size', 'attachurl', 'uploadtime', 'descrip');
 $ArrValue = array($fid, $user->uid, 0, $atc_attachment_name, $type, $size, $attachdir . '/' . $fileuplodeurl, TIMESTAMP, $descrip);
 if ($MyDatabase->Insert('attachs', $ArrField, $ArrValue)) {
     $aid = $MyDatabase->Insert_id();
     $descrip = str_replace('\\', '', $descrip);
     if ($descrip != '') {
         $str_att .= "\n[b]" . str_replace('\\', '', $descrip) . "[/b]";
Пример #2
0
function UploadFile($uid, $uptype = 'all', $thumbs = null)
{
    //fix by noizy
    global $ifupload, $db_attachnum, $db_uploadfiletype, $action, $replacedb, $winddb, $_G, $tdtime, $timestamp, $fid, $db_attachdir, $attachdir, $db_watermark, $db_waterwidth, $db_waterheight, $db_ifgif, $db_waterimg, $db_waterpos, $db_watertext, $db_waterfont, $db_watercolor, $db_waterpct, $db_jpgquality, $db_ifathumb, $db_iffthumb, $db_athumbsize, $db_fthumbsize, $db_ifftp, $atc_attachment_name, $attach_ext, $savedir, $forumset;
    $uploaddb = array();
    foreach ($_FILES as $key => $value) {
        if (if_uploaded_file($value['tmp_name'])) {
            list($t, $i) = explode('_', $key);
            $i = (int) $i;
            $atc_attachment = $value['tmp_name'];
            $atc_attachment_name = S::escapeChar($value['name']);
            $atc_attachment_size = $value['size'];
            $attach_ext = strtolower(substr(strrchr($atc_attachment_name, '.'), 1));
            if (empty($attach_ext) || !isset($db_uploadfiletype[$attach_ext])) {
                uploadmsg($uptype, 'upload_type_error');
            }
            if ((int) $atc_attachment_size < 1) {
                uploadmsg($uptype, 'upload_size_0');
            }
            if ($db_uploadfiletype[$attach_ext] && $atc_attachment_size > $db_uploadfiletype[$attach_ext] * 1024) {
                uploadmsg($uptype, 'upload_size_error');
            }
            if ($uptype == 'face') {
                $ifreplace = 0;
                $db_attachdir = 1;
                $db_ifathumb = $db_iffthumb;
                $db_athumbsize = $db_fthumbsize;
                $savedir = $thumbdir = '';
                $tmpname = $uptype . "_{$uid}.{$attach_ext}";
                $savedir = 'upload/' . str_pad(substr($uid, -2), 2, '0', STR_PAD_LEFT);
                $fileuplodeurl = $thumbdir = "{$savedir}/{$uid}.{$attach_ext}";
            } elseif ($uptype == 'cnlogo') {
                $ifreplace = $db_ifathumb = 0;
                $db_attachdir = 1;
                $savedir = 'cn_img';
                $tmpname = $uptype . "_{$uid}.{$attach_ext}";
                $fileuplodeurl = "{$savedir}/colony_{$uid}.{$attach_ext}";
                $thumbdir = '';
            } elseif ($uptype == 'forumlogo') {
                $ifreplace = 0;
                $db_attachdir = 1;
                $db_ifathumb = 0;
                $tmpname = $uptype . "_{$uid}.{$attach_ext}";
                $savedir = 'forumlogo';
                $fileuplodeurl = "{$savedir}/{$fid}.{$attach_ext}";
            } elseif ($uptype == 'photo') {
                if ($t == 'replace') {
                    $ifreplace = 1;
                    $fileuplodeurl = $replacedb[$i];
                    $tmpurl = strrchr($fileuplodeurl, '/');
                    $fileuplodename = $tmpurl ? substr($tmpurl, 1) : $fileuplodeurl;
                    $tmpname = $uptype . "_{$fileuplodename}";
                } else {
                    $ifreplace = 0;
                    $uid .= substr(md5($timestamp . $i . randstr(8)), 10, 15);
                    $tmpname = $uptype . "_{$uid}.{$attach_ext}";
                    $fileuplodeurl = $fileuplodename = "{$uid}.{$attach_ext}";
                    $db_ifathumb = 1;
                    if ($db_attachdir) {
                        $savedir = 'photo/';
                        if ($db_attachdir == 2) {
                            $savedir .= 'Day_' . date('ymd');
                        } elseif ($db_attachdir == 3) {
                            $savedir .= "Cyid_{$GLOBALS['cyid']}";
                        } else {
                            $savedir .= 'Mon_' . date('ym');
                        }
                        $fileuplodeurl = $savedir . '/' . $fileuplodeurl;
                    }
                }
                $thumbdir = str_replace($fileuplodename, 's_' . $fileuplodename, $fileuplodeurl);
            } else {
                if ($action == 'modify' && $t == 'replace' && isset($replacedb[$i])) {
                    $ifreplace = 1;
                    $fileuplodeurl = $replacedb[$i]['attachurl'];
                    $tmpurl = strrchr($fileuplodeurl, '/');
                    $tmpname = $uptype . '_' . ($tmpurl ? substr($tmpurl, 1) : $fileuplodeurl);
                } else {
                    $ifreplace = 0;
                    $attach_ext = preg_replace('/(php|asp|jsp|cgi|fcgi|exe|pl|phtml|dll|asa|com|scr|inf)/i', "scp_\\1", $attach_ext);
                    $winddb['uploadtime'] = $timestamp;
                    $winddb['uploadnum']++;
                    $prename = substr(md5($timestamp . $i . randstr(8)), 10, 15);
                    $tmpname = $uptype . "_{$prename}.{$attach_ext}";
                    $fileuplodeurl = $fid . "_{$uid}_{$prename}.{$attach_ext}";
                    if ($db_attachdir) {
                        if ($db_attachdir == 2) {
                            $savedir = "Type_{$attach_ext}";
                        } elseif ($db_attachdir == 3) {
                            $savedir = 'Mon_' . date('ym');
                        } elseif ($db_attachdir == 4) {
                            $savedir = 'Day_' . date('ymd');
                        } else {
                            $savedir = "Fid_{$fid}";
                        }
                        $fileuplodeurl = $savedir . '/' . $fileuplodeurl;
                    }
                }
                $thumbdir = "thumb/{$fileuplodeurl}";
            }
            $havefile = $ifthumb = 0;
            if ($db_ifftp || file_exists("{$attachdir}/{$fileuplodeurl}")) {
                $havefile = 1;
                $source = D_P . "data/tmp/{$tmpname}";
            } else {
                $source = "{$attachdir}/{$fileuplodeurl}";
            }
            if (!postupload($atc_attachment, $source)) {
                uploadmsg($uptype, 'upload_error');
            }
            if ($uptype == 'face') {
                $max_source = $attachdir . "/upload/tmp/max_{$tmpname}";
                if (!copy($source, $max_source)) {
                    uploadmsg($uptype, 'upload_error');
                }
                /*
                if (!postupload($atc_attachment,$max_source)) {
                	uploadmsg($uptype,'upload_error');
                }
                */
            }
            $ifupload = 3;
            $type = 'zip';
            $img_size[0] = $img_size[1] = 0;
            $size = ceil(filesize($source) / 1024);
            if (in_array($attach_ext, array('gif', 'jpg', 'jpeg', 'png', 'bmp', 'swf'))) {
                require_once R_P . 'require/imgfunc.php';
                if (!($img_size = GetImgSize($source, $attach_ext))) {
                    P_unlink($source);
                    uploadmsg($uptype, 'upload_content_error');
                }
                $ifupload = 1;
                $img_size[0] = $img_size['width'];
                $img_size[1] = $img_size['height'];
                unset($img_size['width'], $img_size['height']);
                $type = 'img';
                if ($attach_ext == 'swf') {
                    $type = 'zip';
                } elseif ($db_ifathumb) {
                    $thumburl = $havefile ? D_P . "data/tmp/thumb_{$tmpname}" : "{$attachdir}/{$thumbdir}";
                    list($db_thumbw, $db_thumbh) = explode("\t", $db_athumbsize);
                    list($cenTer, $sameFile) = explode("\t", $thumbs);
                    createFolder(dirname($thumburl));
                    if ($thumbsize = MakeThumb($source, $thumburl, $db_thumbw, $db_thumbh, $cenTer, $sameFile)) {
                        $img_size[0] = $thumbsize[0];
                        $img_size[1] = $thumbsize[1];
                        $source != $thumburl && ($ifthumb = 1);
                    }
                }
                if ($uptype == 'all' && $db_watermark && $forumset['watermark'] && $img_size[2] < '4' && $img_size[0] > $db_waterwidth && $img_size[1] > $db_waterheight && function_exists('imagecreatefromgif') && function_exists('imagealphablending') && ($attach_ext != 'gif' || function_exists('imagegif') && ($db_ifgif == 2 || $db_ifgif == 1 && (PHP_VERSION > '4.4.2' && PHP_VERSION < '5' || PHP_VERSION > '5.1.4'))) && ($db_waterimg && function_exists('imagecopymerge') || !$db_waterimg && function_exists('imagettfbbox'))) {
                    ImgWaterMark($source, $db_waterpos, $db_waterimg, $db_watertext, $db_waterfont, $db_watercolor, $db_waterpct, $db_jpgquality);
                    if ($ifthumb == 1) {
                        ImgWaterMark($thumburl, $db_waterpos, $db_waterimg, $db_watertext, $db_waterfont, $db_watercolor, $db_waterpct, $db_jpgquality);
                    }
                }
            } elseif ($attach_ext == 'txt') {
                if (preg_match('/(onload|submit|post|form)/i', readover($source))) {
                    P_unlink($source);
                    uploadmsg($uptype, 'upload_content_error');
                }
                $ifupload = 2;
                $type = 'txt';
            }
            require_once R_P . 'require/functions.php';
            if (pwFtpNew($GLOBALS['ftp'], $db_ifftp) && $GLOBALS['ftp']->upload($source, $fileuplodeurl)) {
                P_unlink($source);
                P_unlink("{$attachdir}/{$fileuplodeurl}");
                if ($ifthumb == 1) {
                    $GLOBALS['ftp']->mkdir("thumb/{$savedir}");
                    $GLOBALS['ftp']->upload($thumburl, $thumbdir) && P_unlink($thumburl);
                }
            } elseif ($havefile) {
                P_unlink("{$attachdir}/{$fileuplodeurl}");
                @rename($source, "{$attachdir}/{$fileuplodeurl}");
                if ($ifthumb == 1) {
                    P_unlink("{$attachdir}/{$thumbdir}");
                    @rename($thumburl, "{$attachdir}/{$thumbdir}");
                }
            }
            $uploaddb[] = array('id' => $i, 'ifreplace' => $ifreplace, 'name' => $atc_attachment_name, 'size' => $size, 'type' => $type, 'attachurl' => $fileuplodeurl, 'ifthumb' => $ifthumb, 'img_w' => $img_size[0], 'img_h' => $img_size[1], 'tmpname' => $tmpname);
        }
    }
    return $uploaddb;
}
Пример #3
0
 if (is_array($upload)) {
     $upload_name = $upload['name'];
     $upload_size = $upload['size'];
     $upload = $upload['tmp_name'];
 }
 $basename .= "&type={$type}";
 if ($upload && $upload != 'none') {
     require_once R_P . 'require/postfunc.php';
     $attach_ext = strtolower(substr(strrchr($upload_name, '.'), 1));
     if (!if_uploaded_file($upload)) {
         adminmsg('upload_error', "{$basename}&action=setting");
     } elseif ($attach_ext != 'txt') {
         adminmsg('upload_type_error', "{$basename}&action=setting");
     }
     $source = D_P . "data/tmp/word.txt";
     if (postupload($upload, $source)) {
         $content = explode("\n", readover($source));
         $wordtime = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
         $success = 0;
         $fail = 0;
         foreach ($content as $key => $value) {
             if ($value) {
                 $word = trim(substr($value, 0, strpos($value, '|')));
                 $type = trim(substr(strrchr($value, '|'), 1));
                 if (!intval($type)) {
                     $fail++;
                     continue;
                 }
                 $id = $db->get_value("SELECT id FROM pw_wordfb WHERE word=" . S::sqlEscape($word));
                 if (empty($id)) {
                     $sql = "INSERT INTO pw_wordfb (word,wordreplace,type,wordtime,classid,custom) VALUES (" . S::sqlEscape($word) . ", '*****', " . S::sqlEscape($type) . ", " . S::sqlEscape($wordtime) . ", " . S::sqlEscape($class) . ", 1)";
Пример #4
0
function UploadDiary($uid, $uptype = 'all', $thumbs = null)
{
    global $ifupload, $db_attachnum, $o_uploadsize, $a, $did, $replacedb, $winddb, $_G, $tdtime, $timestamp, $o_attachdir, $attachdir, $db_watermark, $db_waterwidth, $db_waterheight, $db_ifgif, $db_waterimg, $db_waterpos, $db_watertext, $db_waterfont, $db_watercolor, $db_waterpct, $db_jpgquality, $db_ifathumb, $db_iffthumb, $db_athumbsize, $db_fthumbsize, $atc_attachment_name, $attach_ext, $savedir;
    $uploaddb = array();
    foreach ($_FILES as $key => $value) {
        if (if_uploaded_file($value['tmp_name'])) {
            list($t, $i) = explode('_', $key);
            $i = (int) $i;
            $atc_attachment = $value['tmp_name'];
            $atc_attachment_name = S::escapeChar($value['name']);
            $atc_attachment_size = $value['size'];
            $attach_ext = strtolower(substr(strrchr($atc_attachment_name, '.'), 1));
            if (empty($attach_ext) || !isset($o_uploadsize[$attach_ext])) {
                uploadmsg($uptype, 'upload_type_error');
            }
            if ((int) $atc_attachment_size < 1) {
                uploadmsg($uptype, 'upload_size_0');
            }
            if ($o_uploadsize[$attach_ext] && $atc_attachment_size > $o_uploadsize[$attach_ext] * 1024) {
                $GLOBALS['oversize'] = $o_uploadsize[$attach_ext];
                uploadmsg($uptype, 'upload_size_error');
            }
            if ($a == 'edit' && $t == 'replace' && isset($replacedb[$i])) {
                $ifreplace = 1;
                $fileuplodeurl = $replacedb[$i]['attachurl'];
                $tmpurl = strrchr($fileuplodeurl, '/');
                $tmpname = $uptype . '_' . ($tmpurl ? substr($tmpurl, 1) : $fileuplodeurl);
            } else {
                $ifreplace = 0;
                $attach_ext = preg_replace('/(php|asp|jsp|cgi|fcgi|exe|pl|phtml|dll|asa|com|scr|inf)/i', "scp_\\1", $attach_ext);
                $winddb['uploadtime'] = $timestamp;
                $winddb['uploadnum']++;
                $prename = substr(md5($timestamp . $i . randstr(8)), 10, 15);
                $tmpname = $uptype . "_{$prename}.{$attach_ext}";
                $fileuplodeurl = $uid . "_{$did}_{$prename}.{$attach_ext}";
                if ($o_attachdir) {
                    if ($o_attachdir == 1) {
                        $savedir = "Type_{$attach_ext}";
                    } elseif ($o_attachdir == 2) {
                        $savedir = 'Mon_' . date('ym');
                    } elseif ($o_attachdir == 3) {
                        $savedir = 'Day_' . date('ymd');
                    }
                    $fileuplodeurl = $savedir . '/' . $fileuplodeurl;
                }
            }
            $thumbdir = "thumb/diary/{$fileuplodeurl}";
            $havefile = $ifthumb = 0;
            $source = "{$attachdir}/diary/{$fileuplodeurl}";
            if (!postupload($atc_attachment, $source)) {
                uploadmsg($uptype, 'upload_error');
            }
            $ifupload = 3;
            $img_size[0] = $img_size[1] = 0;
            $size = ceil(filesize($source) / 1024);
            if (in_array($attach_ext, array('gif', 'jpg', 'jpeg', 'png', 'bmp'))) {
                require_once R_P . 'require/imgfunc.php';
                if (!($img_size = GetImgSize($source, $attach_ext))) {
                    P_unlink($source);
                    uploadmsg($uptype, 'upload_content_error');
                }
                $ifupload = 1;
                $img_size[0] = $img_size['width'];
                $img_size[1] = $img_size['height'];
                unset($img_size['width'], $img_size['height']);
                $type = 'img';
                if ($db_ifathumb) {
                    $thumburl = $havefile ? D_P . "data/tmp/thumb_{$tmpname}" : "{$attachdir}/{$thumbdir}";
                    list($db_thumbw, $db_thumbh) = explode("\t", $db_athumbsize);
                    list($cenTer, $sameFile) = explode("\t", $thumbs);
                    createFolder(dirname($thumburl));
                    if ($thumbsize = MakeThumb($source, $thumburl, $db_thumbw, $db_thumbh, $cenTer, $sameFile)) {
                        $img_size[0] = $thumbsize[0];
                        $img_size[1] = $thumbsize[1];
                        $source != $thumburl && ($ifthumb = 1);
                    }
                }
                if ($uptype == 'all' && $db_watermark && $img_size[2] < '4' && $img_size[0] > $db_waterwidth && $img_size[1] > $db_waterheight && function_exists('imagecreatefromgif') && function_exists('imagealphablending') && ($attach_ext != 'gif' || function_exists('imagegif') && ($db_ifgif == 2 || $db_ifgif == 1 && (PHP_VERSION > '4.4.2' && PHP_VERSION < '5' || PHP_VERSION > '5.1.4'))) && ($db_waterimg && function_exists('imagecopymerge') || !$db_waterimg && function_exists('imagettfbbox'))) {
                    ImgWaterMark($source, $db_waterpos, $db_waterimg, $db_watertext, $db_waterfont, $db_watercolor, $db_waterpct, $db_jpgquality);
                    if ($ifthumb == 1) {
                        ImgWaterMark($thumburl, $db_waterpos, $db_waterimg, $db_watertext, $db_waterfont, $db_watercolor, $db_waterpct, $db_jpgquality);
                    }
                }
            }
            if ($havefile) {
                P_unlink("{$attachdir}/diary/{$fileuplodeurl}");
                @rename($source, "{$attachdir}/diary/{$fileuplodeurl}");
                if ($ifthumb == 1) {
                    P_unlink("{$attachdir}/{$thumbdir}");
                    @rename($thumburl, "{$attachdir}/{$thumbdir}");
                }
                if ($m_ifthumb == 1) {
                    //TODO $m_ifthumb?
                    P_unlink("{$attachdir}/{$m_thumbdir}/diary");
                    //TODO $m_thumbdir?
                    @rename($m_thumburl, "{$attachdir}/{$m_thumbdir}/diary");
                    //TODO $m_thumburl?
                }
                if ($s_ifthumb == 1) {
                    //TODO $m_ifthumb?
                    P_unlink("{$attachdir}/{$s_thumbdir}/diary");
                    //TODO $s_thumbdir?
                    @rename($s_thumburl, "{$attachdir}/{$s_thumbdir}/diary");
                    //TODO $s_thumburl?
                }
            }
            $uploaddb[] = array('id' => $i, 'ifreplace' => $ifreplace, 'name' => $atc_attachment_name, 'size' => $size, 'type' => $type, 'attachurl' => $fileuplodeurl, 'ifthumb' => $ifthumb, 'img_w' => $img_size[0], 'img_h' => $img_size[1]);
        }
    }
    return $uploaddb;
}