哈哈不负有心人,不断尝试,终于弄懂zblog什么回事..................
/**
* @param $tmp
* 保存文件,使用绝对路径,使用服务器路径
*
* @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 . "cdns/" . $this->Dir)) { //$zbp->usersdir
@mkdir(ZBP_PATH . "cdns/" . $this->Dir, 0755, true); //$zbp->usersdir
}
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 . "cdns/" . $this->Dir . $fn); //$zbp->usersdir
return true;
}
return true;
}
/**
* @param $str64
* * 保存文件,使用绝对路径,使用服务器路径
* @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;
}
}
if (!file_exists(ZBP_PATH . "cdns/" . $this->Dir)) {
@mkdir(ZBP_PATH . "cdns/" . $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 . "cdns/" . $this->Dir . $fn, $s); //$zbp->usersdir
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
*
* @return Member|mixed|string
*/
public function __get($name)
{
global $zbp;
if ($name == 'Url') {
foreach ($GLOBALS['hooks']['Filter_Plugin_Upload_Url'] as $fpname => &$fpsignal) {
return $fpname($this);
}
return $zbp->host ."cdns/" . $this->Dir . rawurlencode($this->Name);
}
// return "https://imgs.wagf.cn/cdns/" . $this->Dir . rawurlencode($this->Name); //cdn域名访问
// return $zbp->host ."cdns/" . $this->Dir . rawurlencode($this->Name); //本域名访问.
if ($name == 'Dir') {
foreach ($GLOBALS['hooks']['Filter_Plugin_Upload_Dir'] as $fpname => &$fpsignal) {
return $fpname($this);
}
$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 $zbp->host . "cdns/" . $this->Dir . $this->Name;
}
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;
}
}有空再研究....