You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.0 KiB
PHP
43 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace app\admin\model;
|
|
use think\Model;
|
|
class Article extends Model
|
|
{
|
|
protected static function init()
|
|
{
|
|
Article::event('before_insert',function($article){
|
|
if($_FILES['thumb']['tmp_name']){
|
|
$file = request()->file('thumb');
|
|
$info = $file->move(ROOT_PATH .'public'.DS .'uploads');
|
|
if($info){
|
|
$thumb='/bick/'.'public'.DS .'uploads'.'/'.$info->getSaveName();
|
|
$article['thumb']=$thumb;
|
|
}
|
|
}
|
|
});
|
|
Article::event('before_update',function($article){
|
|
if($_FILES['thumb']['tmp_name']){
|
|
$arts=Article::find($article->id);
|
|
$thumbpath=$_SERVER['DOCUMENT_ROOT'].$arts['thumb'];
|
|
if(file_exists($thumbpath)){
|
|
@unlink($thumbpath);
|
|
}
|
|
$file = request()->file('thumb');
|
|
$info = $file->move(ROOT_PATH .'public'.DS .'uploads');
|
|
if($info){
|
|
$thumb='/bick/'.'public'.DS .'uploads'.'/'.$info->getSaveName();
|
|
$article['thumb']=$thumb;
|
|
}
|
|
}
|
|
});
|
|
Article::event('before_delete',function($article){
|
|
$arts=Article::find($article->id);
|
|
$thumbpath=$_SERVER['DOCUMENT_ROOT'].$arts['thumb'];
|
|
if(file_exists($thumbpath)){
|
|
@unlink($thumbpath);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
?>
|