xhEditor 換成域名xhEditor.com 不指定

Else , 2009/10/29 10:15 , 代码片段,演示也有 , Comments(0) , Reads(608) , Via Original
Quotation
默认模式:http://xheditor.com/demos/demo1.html
自定义按钮:http://xheditor.com/demos/demo2.html
皮肤选择:http://xheditor.com/demos/demo3.html
其它选项:http://xheditor.com/demos/demo4.html
Javascript交互:http://xheditor.com/demos/demo5.html
非utf-8编码网页调用:http://xheditor.com/demos/demo6.html
UBB可视化编辑:http://xheditor.com/demos/demo7.html
Ajax文件上传:http://xheditor.com/demos/demo8.html
插件扩展:http://xheditor.com/demos/demo9.html
iframe调用文件上传:http://xheditor.com/demos/demo10.html


下面為upload.php的修改

Quotation
/*!
* upload demo for php
* @requires xhEditor
*
* @author Yanis.Wang
* @site http://pirate9.com/
* @licence LGPL(http://www.opensource.org/licenses/lgpl-license.php)
*
* 注:本程序仅为演示用,请您根据自己需求进行相应修改,或者重开发。
*/
header('Content-Type: text/html; charset=UTF-8');

function uploadfile($inputname) {
    $attachdir='attached';//上传文件保存路径,结尾不要带/
    $dirtype=2;//1:按天存入目录 2:按月存入目录 3:按扩展名存目录  建议使用按天存
    $maxattachsize=2097152;//最大上传大小,默认是2M
   $uptypes=array('image/jpg',  //上传文件类型列表
        'image/jpeg',
        'image/png',
        'image/pjpeg',
        'image/gif',
        'image/bmp',
        'application/x-shockwave-flash',
        'image/x-png');

    $err = "";
    $msg = "";
    $upfile=$_FILES[$inputname];


    if(!empty($upfile['error'])) {
        switch($upfile['error']) {
            case '1':
                $err = '文件大小超过了php.ini定义的upload_max_filesize值';
                break;
            case '2':
                $err = '文件大小超过了HTML定义的MAX_FILE_SIZE值';
                break;
            case '3':
                $err = '文件上传不完全';
                break;
            case '4':
                $err = '无文件上传';
                break;
            case '6':
                $err = '缺少临时文件夹';
                break;
            case '7':
                $err = '写文件失败';
                break;
            case '8':
                $err = '上传被其它扩展中断';
                break;
            case '999':
            default:
                $err = '无有效错误代码';
        }
    }
   elseif(!in_array($upfile["type"], $uptypes))   //检查文件类型
    {
        $err = '只能上传图片';

    }

    elseif(empty($upfile['tmp_name']) || $upfile['tmp_name'] == 'none') {
        $err = '无文件上传';
    }
    else {
        $temppath=$upfile['tmp_name'];
        $fileinfo=pathinfo($upfile['name']);
        $extension=$fileinfo['extension'];
        $filesize=filesize($temppath);
        if($filesize <= $maxattachsize) {
            switch($dirtype) {
                case 1: $attach_subdir = 'day_'.date('ymd'); break;
                case 2: $attach_subdir = 'month_'.date('ym'); break;
                case 3: $attach_subdir = 'ext_'.$extension; break;
            }
            $attach_dir = $attachdir.'/'.$attach_subdir;
            if(!is_dir($attach_dir)) {
                @mkdir($attach_dir, 0777);
                @fclose(fopen($attach_dir.'/index.htm', 'w'));
            }
            PHP_VERSION < '4.2.0' && mt_srand((double)microtime() * 1000000);
            $filename=date("YmdHis").mt_rand(1000,9999).'.'.$extension;
            $target = $attach_dir.'/'.$filename;

            move_uploaded_file($upfile['tmp_name'],$target);
            $msg='/'.$target;
        }
        else $err='文件大小超过'.$maxattachsize.'字节';

        @unlink($temppath);
    }
    return array('err'=>$err,'msg'=>$msg);
}

$state=uploadfile('upload');
echo json_encode($state);
?>
Add a comment

Nickname

Site URI

Email

Enable HTML Enable UBB Enable Emots Hidden Remember [Login] [Register]