当前位置:首页 > 编程技术 > PHP编程

zblog - php -upload

网友投稿2年前 (2024-04-09)PHP编程1515
摘要:zblog 编程实例<?php if (!defined('ZBP_PATH')) {     exit('Access denied'); } /**  *&nb…

zblog 编程实例

<?php

if (!defined('ZBP_PATH')) {
    exit('Access denied');
}

/**
 * 上传类.
 *
 * @property string Name
 * @property string FullFile
 * @property string Size
 * @property string Dir
 * @property int PostTime
 * @property int|string AuthorID
 * @property string SourceName
 * @property string MimeType
 * @property Member Author
 */
abstract class Base__Upload extends Base
{

    public function __construct()
    {
        global $zbp;
        parent::__construct($zbp->table['Upload'], $zbp->datainfo['Upload'], __CLASS__);

        $this->PostTime = time();
    }

    /**
     * @param string $extList
     *
     * @return bool
     */
    public function CheckExtName($extList = '')
    {
        global $zbp;
        $fn = $this->Name;
        if (stripos($fn, '.htaccess') !== false) {
            return false;
        }
        if (stripos($fn, 'web.config') !== false) {
            return false;
        }
        $e = GetFileExt($this->Name);
        $extList = strtolower($extList);
        // 无论如何,禁止.php、.php5之类的文件的上传
        if (preg_match('/php/i', $e)) {
            return false;
        }
        if (preg_match('/pht(ml)?(\d*)|phar/i', $e)) {
            return false;
        }
        if (trim($extList) == '') {
            $extList = $zbp->option['ZC_UPLOAD_FILETYPE'];
        }

        return HasNameInString($extList, $e);
    }

    /**
     * @return bool
     */
    public function CheckSize()
    {
        global $zbp;
        $n = (1024 * 1024 * (int) $zbp->option['ZC_UPLOAD_FILESIZE']);

        return $n >= $this->Size;
    }

    /**
     * @return bool
     */
    public function DelFile()
    {
        foreach ($GLOBALS['hooks']['Filter_Plugin_Upload_DelFile'] as $fpname => &$fpsignal) {
            $fpreturn = $fpname($this);
            if ($fpsignal == PLUGIN_EXITSIGNAL_RETURN) {
                $fpsignal = PLUGIN_EXITSIGNAL_NONE;

                return $fpreturn;
            }
        }
        if (file_exists($this->FullFile)) {
            @unlink($this->FullFile);
        }

        return true;
    }

   /**
     * @param $tmp
     * //保存文件,使用绝对路径,使用服务器路径
     * //$zbp->usersdir 
     * // ZBP_PATH . "9892_cdns_1/" 
     * @return bool
     */
    public function SaveFile($tmp)
    {
        global $zbp;

        foreach ($GLOBALS['hooks']['Filter_Plugin_Upload_SaveFile'] as $fpname => &$fpsignal) {
            $fpreturn = $fpname($tmp, $this);
            if ($fpsignal == PLUGIN_EXITSIGNAL_RETURN) {
                $fpsignal = PLUGIN_EXITSIGNAL_NONE;

                return $fpreturn;
            }
        }

      if (!file_exists( ZBP_PATH . "9892_cdns_1/" . $this->Dir)) {
            @mkdir( ZBP_PATH . "9892_cdns_1/" . $this->Dir, 0755, true);
        }
        if (PHP_SYSTEM === SYSTEM_WINDOWS) {
            $fn = iconv("UTF-8", $zbp->lang['windows_character_set'] . "//IGNORE", $this->Name);
        } else {
            $fn = $this->Name;
        }
        if ($this->CheckExtName()) {
            @move_uploaded_file($tmp,  ZBP_PATH . "9892_cdns_1/" . $this->Dir . $fn);
            return true;
        }

        return true;
    }

    /**
     * @param $str64
     * //保存文件,使用绝对路径,使用服务器路径
     * //$zbp->usersdir 
     * // ZBP_PATH . "9892_cdns_1/" 
     * @return bool
     */
    public function SaveBase64File($str64)
    {
        global $zbp;

        foreach ($GLOBALS['hooks']['Filter_Plugin_Upload_SaveBase64File'] as $fpname => &$fpsignal) {
            $fpreturn = $fpname($str64, $this);
            if ($fpsignal == PLUGIN_EXITSIGNAL_RETURN) {
                $fpsignal = PLUGIN_EXITSIGNAL_NONE;

                return $fpreturn;
            }
        }
 // ZBP_PATH . "9892_cdns/" 
        if (!file_exists( ZBP_PATH . "9892_cdns_1/" . $this->Dir)) {
            @mkdir( ZBP_PATH . "9892_cdns_1/" . $this->Dir, 0755, true);
        }
        $s = base64_decode($str64);
        $this->Size = strlen($s);
        if (PHP_SYSTEM === SYSTEM_WINDOWS) {
            $fn = iconv("UTF-8", "GBK//IGNORE", $this->Name);
        } else {
            $fn = $this->Name;
        }
        if ($this->CheckExtName()) {
            file_put_contents( ZBP_PATH . "9892_cdns_1/" . $this->Dir . $fn, $s); // ZBP_PATH . "9892_cdns_1/" 
            return true;
        }
    }

    /**
     * @param string $s
     *
     * @return bool|string
     */
    public function Time($s = 'Y-m-d H:i:s')
    {
        return date($s, $this->PostTime);
    }

    /**
     * @param $name
     * @param $value
     */
    public function __set($name, $value)
    {
        if (in_array($name, array('Url', 'Dir', 'FullFile', 'Author'))) {
            return;
        }
        foreach ($GLOBALS['hooks']['Filter_Plugin_Upload_Set'] as $fpname => &$fpsignal) {
            $fpname($this, $name, $value);
        }
        parent::__set($name, $value);
    }

    /**
     * @param $name
     * //$zbp->host . 'zb_users/' .
     * //"https://cdn.wagf.cn/"
     * @return Member|mixed|string
     */
    public function __get($name)
    {
        global $zbp;
        //注:这里原先设计失误,没有判断接口函数返回值就直接return,造成了插件必须自己拼接所有的url,不管接管还是不接管
        //1.7.3后修改为先判断null,如果返回null就交给下一棒直到返回系统默认值
        //Filter_Plugin_Upload_Url和Filter_Plugin_Upload_Dir都做了同样的修复
        if ($name == 'Url') {
            foreach ($GLOBALS['hooks']['Filter_Plugin_Upload_Url'] as $fpname => &$fpsignal) {
                $furl = $fpname($this);
                if (!empty($furl)) {
                    return $furl;
                }
            }

           return "https://imgs.178d.com/" . $this->Dir . rawurlencode($this->Name);  //https://cdn.wagf.cn/ .
        }
        if ($name == 'Dir') {
            foreach ($GLOBALS['hooks']['Filter_Plugin_Upload_Dir'] as $fpname => &$fpsignal) {
                $fdir = $fpname($this);
                if (!empty($fdir)) {
                    return $fdir;
                }
            }
            $dir = 'upload/' . date('Y', $this->PostTime) . '/' . date('m', $this->PostTime) . '/';
            if ($zbp->option['ZC_UPLOAD_DIR_YEARMONTHDAY']) {
                $dir .= date('d', $this->PostTime) . '/';
            }
            return $dir;
        }
        if ($name == 'FullFile') {
            return   "https://imgs.178d.com/" . $this->Dir . $this->Name; //https://cdn.wagf.cn/ .
        }
        if ($name == 'Author') {
            return $zbp->GetMemberByID($this->AuthorID);
        }

        foreach ($GLOBALS['hooks']['Filter_Plugin_Upload_Get'] as $fpname => &$fpsignal) {
            $fpreturn = $fpname($this, $name);
            if ($fpsignal == PLUGIN_EXITSIGNAL_RETURN) {
                $fpsignal = PLUGIN_EXITSIGNAL_NONE;

                return $fpreturn;
            }
        }

        return parent::__get($name);
    }

    /**
     * @return bool
     */
    public function Del()
    {
        foreach ($GLOBALS['hooks']['Filter_Plugin_Upload_Del'] as $fpname => &$fpsignal) {
            $fpreturn = $fpname($this);
            if ($fpsignal == PLUGIN_EXITSIGNAL_RETURN) {
                $fpsignal = PLUGIN_EXITSIGNAL_NONE;

                return $fpreturn;
            }
        }

        return parent::Del();
    }

    /**
     * 获取该附件图片缩略图.
     *
     * @param integer $width
     * @param integer $height
     * @param boolean $clip
     * @return string|null
     */
    public function Thumb($width = 200, $height = 150, $clip = true)
    {
        if (strpos($this->MimeType, 'image') === false) {
            return null;
        }

        $thumbs = Thumb::Thumbs(array($this->Url), $width, $height, 1, $clip);
        return isset($thumbs[0]) ? $thumbs[0] : null;
    }

}


扫描二维码推送至手机访问。

版权声明:本文由天涯家园HomeH发布,如需转载请注明出处。

本文链接:https://www.homeh.cc/post/153.html

分享给朋友:

“zblog - php -upload” 的相关文章

MySQL存储引擎InnoDB与Myisam的六大

摘要: MySQL有多种存储引擎,每种存储引擎有各自的优缺点,可以择优选择使用:MyISAM、InnoDB、MERGE、MEMORY(HEAP)、BDB(BerkeleyDB)、EXAMPLE、FEDERATED、ARCHIVE、CSV、BLACKHOLE。MySQL 有多种存储引擎,每种存储引擎有…

开源CMS软件AKCMS的页眉如何修改

很多免费开源CMS软件都会在自己的作品页眉中加上自己的版权信息,比如ecms,dedecms,ecshop,discuz,会在你的网站中某个地方插入powered by xxoo这种字眼。AKCMS是怎么插入的呢?要如何修改呢,其中有2个地方:1,他会在你每个网页底部强行插入powered by a…

值得推荐的国内外的开源 PHP CMS 系统有哪些?

值得推荐的国内外的开源 PHP CMS 系统有哪些?

开源的网站系统很多,今天就统计整理一下现在流行的各种开源系统、cms推荐,分享给大家参考使用,如果大家有好的资源分享,也请在本文留言评论!一 国内CMS1.cms系统1)知名cmsdedecms: www.dedecms.com/优点:免费开源、简单易上手、前后台分离、前台模版标签、可安装主题插件、…

PHP程序中->和=>是什么意思,怎样理解

在学习PHP中,遇到了->和=>这两个符号。 PHP程序中->和=>是什么意思,怎样理解, 刚遇到这两个符号的时候不知道它们代表的含义,在经过百度后才发这两个符号的秘密。 下面来看一下在PHP中->的秘密,如下代码。 <?phpcla…

[php编程]php中运行后怎么停,php停止脚本运行的操作方法

php停止脚本运行的操作方法发布时间:2020-07-21 17:32:33来源:亿速云阅读:112作者:小新本篇文章和大家了解一下php停止脚本运行的操作方法。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。php停止脚本运行的方法是:return、die、exit。如果exit用…

PHP字符串拼接的使用(连接)[php编程]

PHP 中可以使用字符串连接符.来拼接字符串,它可以把两个或两个以上的字符串拼接成一个新的字符串。字符串拼接有两种形式,分别是直接使用字符串连接符.和赋值运算符.=。具体语法格式如下:$string = string1.string2.string3. ···…