文本版|topic 高级搜索
   名人堂 帮助 论坛制度 意见反馈 | 首页 博客 周新贴 专题 求职 读书
RSS 底部
 
社区导航: 专家门诊   网络技术   操作系统   数据库   程序设计   系统应用   考试认证   CIO及信息化   站长交流   综合交流   下载基地  51CTO产品服务 设为首页 | 收藏本站
51CTO技术论坛» Php » PHP上传类       [ 打印]  [ 订阅]  [ 收藏]  [ 推荐给朋友]   [ 本帖文本页]

论坛跳转:
     
标题: [转载] PHP上传类  ( 查看:319  回复:0 )   
 
gigi
新新人类  点击可查看详细


帖子 24
精华 0
无忧币 96
积分 64
阅读权限 20
注册日期 2007-1-15
最后登录 2007-12-15 离线

[查看资料]  [发短消息]  [Blog
       
发表于:2007-11-21 12:01   标题:PHP上传类
上一帖 |
SaveTo(realpath("./") . "/", $overwrite);
    }
    function SaveTo($uploadDir, $overwrite = 1) {
        //$isOK[0] = false;
        $i = 0;
        foreach ($_FILES as $file) {
            if ($this->checkFileSize($file) && $this->checkFileType($file) && $this->checkFileExt($file)) {
                if ($overwrite || !file_exists($uploadDir . $file['name']))
                    if (move_uploaded_file($file['tmp_name'], $uploadDir . $file['name']))
                        $isOK[$i] = true;
                    else
                        $isOK[$i] = false;
                else
                    $isOK[$i] = false;
            }
            else
                $isOK[$i] = false;
            $i++;
        }
        return $isOK;
    }
    function fileSave($formFile, $overwrite = 1) {
        return $this->fileSaveTo($formFile, realpath("./") . "/", $overwrite);
    }
    function fileSaveTo($formFile, $uploadDir, $overwrite = 1) {
        return $this->fileSaveAs($formFile, $uploadDir, $_FILES[$formFile]['name'], $overwrite);
    }
    function fileSaveAs($formFile, $uploadDir, $fileName, $overwrite = 1) {
        $isOK = true;
        $file = $_FILES[$formFile];
        if ($this->checkFileSize($file) && $this->checkFileType($file) && $this->checkFileExt($file)) {
            if ($overwrite || !file_exists($uploadDir . $fileName))
                if (!move_uploaded_file($file['tmp_name'], $uploadDir . $fileName))
                    $isOK = false;
            else
                $isOK = false;
        }
        else
            $isOK = false;
        return $isOK;
    }
    function setRefuseType($refuseType) {
        $this->refuseType = $refuseType;
    }
    function setAcceptType($acceptType) {
        $this->acceptType = $acceptType;
    }
    function checkFileType($file) {
        if ($this->acceptType != "")
            if (!eregi($this->getFileType($file['type']), $this->acceptType))
                return false;
        if ($this->refuseType != "")
            if (eregi($this->getFileType($file['type']), $this->refuseType))
                return false;
        return true;
    }
    function getFileType($fileType) {
        $i = strrpos($fileType, "/");
        if ($i > 0)
            return substr($fileType, 0, $i);
        else
            return "";
    }
    function setRefuseExt($refuseExt) {
        $this->refuseExt = $refuseExt;
    }
    function setAcceptExt($acceptExt) {
        $this->acceptExt = $acceptExt;
    }
    function checkFileExt($file) {
        if ($this->acceptExt != "")
            if (!eregi($this->getFileExt($file['name']), $this->acceptExt))
                return false;
        if ($this->refuseExt != "")
            if (eregi($this->getFileExt($file['name']), $this->refuseExt))
                return false;
        return true;
    }
    function getFileExt($fileName) {
        $i = strrpos($fileName, ".");
        if ($i > 0)
            return substr($fileName, $i + 1);
        else
            return "";
    }
    function setFileMaxSize($fileMaxSize) {
        $this->fileMaxSize = $fileMaxSize;
    }
    function checkFileSize($file) {
        if ($file['size'] > 0) {
            if ($this->fileMaxSize > 0)
                if ($file['size'] > $this->fileMaxSize)
                    return false;
            return true;
        }
        return false;
    }
    function getFileName($formFile) {
        return $_FILES[$formFile]['name'];
    }
    function getFileNames() {
        $i = 0;
        foreach ($_FILES as $file) {
            $fileNames[$i] = $file['name'];
            $i++;
        }
        return $fileNames;
    }
}
?>



边测边学DB2,把握数据库应用最前沿(豪华大礼:罗技炫酷键鼠、50份卓越礼卡!)
2007-11-21 12:011楼
[ 顶部 ]
     
论坛跳转:  

| | |

标记已读 · 删除论坛Cookies · 文本版 · WAP
 
| 诚征版主 | 版主堂 | 意见建议 | 大史记 | 论坛地图
Copyright©2005-2008 51CTO.COM  Powered by Discuz!
本论坛言论纯属发布者个人意见,不代表51CTO网站立场!如有疑义,请与管理员联系。
京ICP备05051492号