创建版本

This commit is contained in:
2021-02-22 12:17:00 +08:00
commit af555f49c3
2332 changed files with 369202 additions and 0 deletions
@@ -0,0 +1,344 @@
<?php namespace Gdoo\File\Controllers;
use Request;
use Validator;
use DB;
use Auth;
use Session;
use URL;
use Gdoo\File\Models\Attachment;
use Gdoo\Index\Controllers\DefaultController;
class AttachmentController extends DefaultController
{
public $permission = ['preview', 'download', 'draft', 'fileinfo', 'create', 'uploader', 'delete', 'show'];
public function __construct()
{
$PHPSESSID = Request::get('PHPSESSID');
if ($PHPSESSID) {
Session::setId($PHPSESSID);
Session::start();
}
parent::__construct();
}
/**
* 添加文件到草稿
*/
public function draftAction()
{
set_time_limit(0);
$file = Request::file('Filedata');
$mime_type = $this->setting['upload_type'];
$validator = Validator::make(
array('file' => $file),
array('file' => 'mimes:'.$mime_type)
);
if ($validator->passes()) {
// 上传文件的模块名
$module = Request::get('module');
$path = $module.'/'.date('Y/m');
$upload_path = upload_path().'/'.$path;
// 扩展名称
$extension = $file->getClientOriginalExtension();
// 附件新名字
$filename = date('dhis_').str_random(4).'.'.$extension;
$filename = mb_strtolower($filename);
$uploadSuccess = $file->move($upload_path, $filename);
if ($uploadSuccess) {
// 数据库写入
$draft = new Attachment;
$draft->name = mb_strtolower($file->getClientOriginalName());
$draft->path = $path.'/'.$filename;
$draft->type = $extension;
$draft->size = $file->getClientSize();
$draft->save();
return $draft->id;
}
return 0;
}
return 0;
}
/**
* 查看文件
*/
public function fileinfoAction()
{
$id = Request::get('id', 0);
$type = Request::get('type', 0);
$ismobile = Request::get('ismobile', 0);
if ($id > 0) {
$file = Attachment::where('id', $id)->first();
$path = upload_path($file->path);
if (!is_file($path)) {
return $this->json('文件不存在。');
}
//$isimg = '|jpg|png|gif|bmp|jpeg|', '|'.$ext.'|';
//$isoffice = '|doc|docx|xls|xlsx|ppt|pptx|pdf|', '|'.$ext.'|';
//$isbianju = '|doc|docx|xls|xlsx|ppt|pptx|', '|'.$ext.'|';
//$isyulan = ',txt,log,html,htm,js,php,php3,mp4,md,cs,sql,java,json,css,asp,aspx,shtml,cpp,c,vbs,jsp,xml,bat,ini,conf,sh,', ','.$ext.',';
$isview = 0;
$isimg = ['jpg', 'jpeg', 'png', 'gif', 'bmp'];
if (in_array($file['type'], $isimg)) {
$isview = 1;
}
if ($type == 1) {
return $this->json([
'url' => url('file/attachment/download', ['id' => $id]),
'fileext' => $file['type'],
'type' => $type,
'filename' => $file['name'],
'isview' => $isview,
], true);
}
if ($type == 0) {
if ($isview) {
return $this->json([
'url' => url('file/attachment/preview', ['id' => $id]),
'fileext' => $file['type'],
'filename' => $file['name'],
'isview' => $isview,
], true);
} else {
return $this->json('此'.$file['type'].'类型文件不支持在线预览');
}
}
}
}
public function removeAction()
{
$id = Request::get('id', 0);
if ($id > 0) {
$row = Attachment::where('id', $id)->first();
if ($row->path) {
$file = upload_path($row->path);
if (is_file($file)) {
unlink($file);
}
$row->delete();
return 1;
}
}
return 0;
}
public function uploaderAction()
{
set_time_limit(0);
if (Request::method() == 'POST') {
$upload_type = $this->setting['upload_type'];
$upload_max = $this->setting['upload_max'] * (1024 * 1024);
$gets = Request::all();
$file = Request::file('file');
// 上传文件开始
if ($file->isValid()) {
$size = $file->getSize();
$name = $file->getClientOriginalName();
$extension = strtolower($file->getClientOriginalExtension());
//$name = $paths['filename'];
//$extension = strtolower($name);
//$_FILES['Filedata']['size']
// 保存附件的表名
$table = empty($gets['model']) ? 'attachment' : $gets['model'];
// 获取当前要传的基础路径
$path = empty($gets['path']) ? date('Y/m') : $gets['path'].date('/Y/m');
// 附件存放目录
$upload_path = upload_path($path);
/*
if(!is_dir($upload_path)) {
mkdir($upload_path, 0755, true);
}
*/
// 附件新名字
$filename = date('ymdhi').str_random(4).".".$extension;
if (in_array($extension, explode(',', $upload_type))) {
// 移动文件
if ($file->move($upload_path, $filename)) {
$data = [
'title' => $name,
'path' => $path,
'type' => $extension,
'name' => $filename,
'size' => $size,
'add_time' => time(),
'add_user_id' => Auth::id(),
];
$insert_id = DB::table($table)->insertGetId($data);
$data['id'] = $insert_id;
return response()->json($data);
}
}
return response()->json([]);
}
}
$query = Request::all();
$SERVER_URL = url("file/attachment/uploader", $query);
return $this->render([
'SERVER_URL' => $SERVER_URL,
]);
}
public function addAction()
{
set_time_limit(0);
$upload_type = $this->setting['upload_type'];
$upload_max = $this->setting['upload_max']*(1024*1024);
$gets = Request::all();
// 上传文件开始
if (Request::file('Filedata')->isValid()) {
$file = Request::file('Filedata');
$size = $file->getSize();
$name = $file->getClientOriginalName();
$extension = strtolower($file->getClientOriginalExtension());
//$name = $paths['filename'];
//$extension = strtolower($name);
//$_FILES['Filedata']['size']
// 保存附件的表名
$table = empty($gets['model']) ? 'attachment' : $gets['model'];
// 获取当前要传的基础路径
$path = empty($gets['path']) ? date('Y/m') : $gets['path'].date('/Y/m');
// 附件存放目录
$upload_path = upload_path($path);
/*
if(!is_dir($upload_path)) {
mkdir($upload_path, 0755, true);
}
*/
// 附件新名字
$filename = date('ymdhi').str_random(4).".".$extension;
if (in_array($extension, explode(',', $upload_type))) {
// 移动文件
if ($file->move($upload_path, $filename)) {
$insert_id = DB::table($table)->insertGetId([
'title' => $name,
'path' => $path,
'type' => $extension,
'name' => $filename,
'size' => $size,
'add_time' => time(),
'add_user_id' => Auth::id(),
]);
return response($insert_id);
}
}
return response('0');
}
}
public function deleteAction()
{
$gets = Request::all();
if ($gets['id'] > 0) {
$table = empty($gets['model']) ? 'attachment' : $gets['model'];
$row = DB::table($table)->find($gets['id']);
if (is_array($row)) {
$file = upload_path($row['path'].'/'.$row['name']);
if (is_file($file)) {
unlink($file);
}
DB::table($table)->where('id', $row['id'])->delete();
return '1';
}
}
return '0';
}
// 预览文件
public function showAction()
{
$id = (int)Request::get('id');
$model = Request::get('model');
$model = empty($model) ? 'attachment' : $model;
$row = DB::table($model)->where('id', $id)->first();
if (empty($row)) {
return $this->error('文件不存在。');
}
$image = upload_path($row['path'].'/'.$row['name']);
if (is_file($image)) {
// 打开文件
$data = file_get_contents($image);
// 输入文件标签
Header('Content-type:image/'.$row['type']);
// 输出文件内容
echo $data;
exit;
} else {
return $this->error('文件不存在。');
}
}
/**
* 预览文件
*/
public function previewAction()
{
$id = Request::get('id');
$file = Attachment::where('id', $id)->first();
$stream = URL::to('uploads').'/'.$file->path.'/'.$file->name;
if (in_array($file->type, array('jpg', 'gif', 'png'))) {
$view = 'image';
} else {
return $this->error('此格式不支持预览。');
}
return $this->display([
'stream' => $stream,
], 'attachment.image');
}
// 下载文件
public function downloadAction()
{
$id = (int)Request::get('id');
$row = DB::table('attachment')->where('id', $id)->first();
if (empty($row)) {
return $this->json('附件不存在。');
}
$file = upload_path($row['path']);
if (is_file($file)) {
// 下载文件
return response()->download($file, $row['name']);
} else {
return $this->json('文件不存在。');
}
}
}
@@ -0,0 +1,152 @@
<?php namespace Gdoo\File\Controllers;
use Gdoo\Index\Controllers\DefaultController;
use DB;
use Request;
use Validator;
use Gdoo\Model\Grid;
use Gdoo\File\Models\Certificate;
class CertificateController extends DefaultController
{
public function indexAction()
{
$header = Grid::header([
'code' => 'file_certificate',
'referer' => 1,
'search' => [],
]);
$cols = $header['cols'];
$cols['actions']['options'] = [[
'name' => '下载',
'action' => 'download',
'display' => 1,
]];
$search = $header['search_form'];
$query = $search['query'];
if (Request::method() == 'POST') {
$model = DB::table($header['table'])->setBy($header);
foreach ($header['join'] as $join) {
$model->leftJoin($join[0], $join[1], $join[2], $join[3]);
}
$model->orderBy($header['sort'], $header['order']);
foreach ($search['where'] as $where) {
if ($where['active']) {
$model->search($where);
}
}
$model->select($header['select']);
$rows = $model->paginate($query['limit'])->appends($query);
$items = Grid::dataFilters($rows, $header, function($item) {
$item['size'] = human_filesize($item['size']);
return $item;
});
return $items->toJson();
}
$header['buttons'] = [
['name' => '删除', 'icon' => 'fa-remove', 'action' => 'delete', 'display' => $this->access['delete']],
];
$header['cols'] = $cols;
$header['tabs'] = Certificate::$tabs;
$header['bys'] = Certificate::$bys;
$header['js'] = Grid::js($header);
return $this->display([
'header' => $header,
]);
}
public function createAction()
{
if (Request::method() == 'POST') {
$file = Request::file('file');
$name = Request::get('name');
$mime_type = $this->setting['upload_type'];
$validator = Validator::make(
['file' => $file, 'name' => $name],
['file' => 'mimes:'.$mime_type, 'name' => 'required']
);
if ($validator->passes()) {
$path = 'certificate/'.date('Y/m');
$upload_path = upload_path().'/'.$path;
// 扩展名称
$extension = $file->getClientOriginalExtension();
// 附件新名字
$filename = date('dhis_').str_random(4).'.'.$extension;
$filename = mb_strtolower($filename);
$uploadSuccess = $file->move($upload_path, $filename);
if ($uploadSuccess) {
// 数据库写入
$draft = new Certificate;
//$draft->name = mb_strtolower($file->getClientOriginalName());
$draft->name = $name;
$draft->path = $path.'/'.$filename;
$draft->type = $extension;
$draft->size = $file->getClientSize();
$draft->save();
return $this->json('文件上传成功。', true);
}
} else {
return $this->json($validator->errors()->first());
}
return $this->json('文件不能为空。');
}
return $this->render();
}
public function downloadAction()
{
$id = (int) Request::get('id', 0);
$row = DB::table('file_certificate')->where('id', $id)->first();
if (empty($row)) {
return $this->error('附件不存在。');
}
$filename = upload_path($row['path']);
if (is_file($filename)) {
// 打开文件
$name = mb_convert_encoding($row['name'], "gbk", "UTF-8");
$file = fopen($filename, "r");
DB::table('file_certificate')->where('id', $id)->increment('hits');
// 输入文件标签
Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
Header("Accept-Length: " . filesize($filename));
Header("Content-Disposition: attachment; filename=" . $name.'.'.$row['type']);
// 输出文件内容
echo fread($file, filesize($filename));
fclose($file);
exit;
} else {
return $this->error('附件文件不存在。');
}
}
public function deleteAction()
{
$id = (array)Request::get('id');
$rows = DB::table('file_certificate')->whereIn('id', $id)->get();
if ($rows->isEmpty()) {
return $this->json('附件不存在。');
} else {
foreach($rows as $row) {
$path = upload_path($row['path']);
if (is_file($path)) {
unlink($path);
}
DB::table('file_certificate')->where('id', $row['id'])->delete();
}
}
return $this->json('文件删除成功。', true);
}
}
@@ -0,0 +1,409 @@
<?php namespace Gdoo\File\Controllers;
use DB;
use Request;
use Validator;
use Gdoo\Index\Models\Share;
use Gdoo\File\Models\File;
use Gdoo\Index\Controllers\DefaultController;
class FileController extends DefaultController
{
public $permission = ['index', 'common', 'share', 'receive', 'receivedata', 'folder', 'upload', 'sharing'];
public $folders = [
['id' => 'common', 'name' => '公共云盘'],
['id' => 'index', 'name' => '个人云盘'],
['id' => 'share', 'name' => '我共享的'],
['id' => 'receive','name' => '我收到的'],
];
public function index1Action()
{
$rows = [
['id' => 'common', 'name' => '公共云盘'],
['id' => 'personal', 'name' => '个人云盘'],
['id' => 'share', 'name' => '我共享的'],
['id' => 'receive', 'name' => '我收到的'],
];
return $this->display([
'rows' => $rows,
]);
}
// 新建文件夹
public function folderAction()
{
$gets = Request::all();
if (Request::method() == 'POST') {
$model = File::findOrNew($gets['id']);
$model->fill($gets)->save();
return $this->json('reload', true);
}
$row = File::find($gets['id']);
$row['parent_id'] = $gets['parent_id'];
$row['folder'] = $gets['folder'];
return $this->render([
'row' => $row,
]);
}
// 共享操作
public function sharingAction()
{
$gets = Request::all();
$file = File::find($gets['id']);
$type = $file['folder'] == 1 ? 'folder' : 'file';
if (Request::method() == 'POST') {
$share_data = [
'source_id' => $gets['id'],
'source_type' => $type,
'receive_id' => $gets['receive_id'],
'receive_name' => $gets['receive_name'],
];
$share = Share::getItem($type, $gets['id']);
if (empty($share)) {
Share::addItem($share_data);
} else {
Share::editItem($type, $gets['id'], $share_data);
}
return $this->json('reload', true);
}
$row = Share::getItem($type, $gets['id']);
$row['id'] = $gets['id'];
return $this->render([
'row' => $row,
]);
}
// 上传文件
public function uploadAction()
{
$parent_id = Request::get('parent_id', 0);
if (Request::method() == 'POST') {
$file = Request::file('Filedata');
$mime_type = $this->setting['upload_type'];
$validator = Validator::make(
['file' => $file],
['file' => 'mimes:'.$mime_type]
);
if ($validator->passes()) {
$path = 'file/'.date('Y/m');
$upload_path = upload_path().'/'.$path;
// 扩展名称
$extension = $file->getClientOriginalExtension();
// 附件新名字
$filename = date('dhis_').str_random(4).'.'.$extension;
$filename = mb_strtolower($filename);
$uploadSuccess = $file->move($upload_path, $filename);
if ($uploadSuccess) {
// 数据库写入
$draft = new File;
$draft->parent_id = $parent_id;
$draft->name = mb_strtolower($file->getClientOriginalName());
$draft->path = $path.'/'.$filename;
$draft->type = $extension;
$draft->size = $file->getClientSize();
$draft->save();
return $draft->id;
}
return 0;
}
return 0;
}
return $this->render([
'parent_id' => $parent_id,
]);
}
// 个人云盘
public function indexAction()
{
$search = search_form([
'referer' => 1,
], []);
$user_id = auth()->id();
$parent_id = Request::get('parent_id', 0);
$rows = DB::table('file')
->where('parent_id', $parent_id)
->where('public', 0)
->where('created_id', $user_id)
->orderBy('folder', 'desc')
->orderBy('created_at', 'desc')
->paginate();
// 获取文件夹路径
$parents = DB::table('file')
->where('public', 0)
->where('folder', 1)
->where('created_id', $user_id)
->get();
$parents = array_nest($parents);
$breadcrumb = [];
if ($parent_id) {
$paths = $parents[$parent_id]['parent'];
foreach ($paths as $path) {
$breadcrumb[] = ['name' => $parents[$path]['name'], 'id' => $path];
}
}
return $this->display([
'rows' => $rows,
'breadcrumb' => $breadcrumb,
'parent_id' => $parent_id,
'folders' => $this->folders,
]);
}
// 共享给我的
public function receiveAction()
{
$user_id = auth()->id();
$shares = Share::getItemsSourceBy(['folder', 'file'], $user_id)->pluck('created_id');
$rows = DB::table('user')->whereIn('id', $shares)->paginate();
return $this->display([
'rows' => $rows,
]);
}
// 共享给我的
public function receivedataAction()
{
$search = search_form([
'referer' => 1,
], []);
$user_id = Request::get('user_id');
$parent_id = Request::get('parent_id');
// 共享的全部文件和文件夹
$shares = Share::getItemsCreatedBy(['folder', 'file'], $user_id)
->pluck('source_id')
->toArray();
$model = DB::table('file')
->where('public', 0)
->where('created_id', $user_id);
if ($parent_id) {
$model->where('parent_id', $parent_id);
} else {
$model->whereIn('id', $shares);
}
$rows = $model->orderBy('folder', 'desc')
->orderBy('created_at', 'desc')
->paginate();
// 获取全部文件夹
$parents = DB::table('file')
->where('public', 0)
->where('folder', 1)
->where('created_id', $user_id)
->get();
// 生成树形数组
$parents = array_nest($parents);
$_shares = array_flip($shares);
$shared = [];
// 获取已经共享的文件夹和文件编号
foreach ($parents as $parent) {
if ($_shares[$parent['id']]) {
$shared = array_merge($shared, $parent['child']);
}
}
$breadcrumb = [];
if ($parent_id) {
// 点开了文件夹
$paths = $parents[$parent_id]['parent'];
// 获取文件夹所有父节编号
foreach ($paths as $path) {
// 有一种情况共享文件夹是子文件夹,必须排除没有共享的父节点
if (in_array($path, $shared)) {
$breadcrumb[] = ['name' => $parents[$path]['name'], 'id' => $path];
}
}
}
$user = $row = DB::table('user')->where('id', $user_id)->first();
return $this->display([
'rows' => $rows,
'breadcrumb' => $breadcrumb,
'parent_id' => $parent_id,
'user' => $user,
]);
}
// 我共享的
public function shareAction()
{
$search = search_form([
'referer' => 1,
], []);
$user_id = Request::get('user_id', auth()->id());
// 共享的全部文件和文件夹
$shares = Share::getItemsCreatedBy(['folder', 'file'], $user_id)
->pluck('source_id')
->toArray();
$parent_id = Request::get('parent_id');
$model = DB::table('file')
->where('public', 0)
->where('created_id', $user_id);
if ($parent_id) {
$model->where('parent_id', $parent_id);
} else {
$model->whereIn('id', $shares);
}
$rows = $model->orderBy('folder', 'desc')
->orderBy('created_at', 'desc')
->paginate();
// 获取全部文件夹
$parents = DB::table('file')
->where('public', 0)
->where('folder', 1)
->where('created_id', $user_id)
->get();
// 生成树形数组
$parents = array_nest($parents);
$_shares = array_flip($shares);
$shared = [];
// 获取已经共享的文件夹和文件编号
foreach ($parents as $parent) {
if ($_shares[$parent['id']]) {
$shared = array_merge($shared, $parent['child']);
}
}
$breadcrumb = [];
if ($parent_id) {
// 点开了文件夹
$paths = $parents[$parent_id]['parent'];
// 获取文件夹所有父节编号
foreach ($paths as $path) {
// 有一种情况共享文件夹是子文件夹,必须排除没有共享的父节点
if (in_array($path, $shared)) {
$breadcrumb[] = ['name' => $parents[$path]['name'], 'id' => $path];
}
}
}
return $this->display([
'rows' => $rows,
'breadcrumb' => $breadcrumb,
'parent_id' => $parent_id,
]);
}
// 公共网盘
public function commonAction()
{
$folder_id = Request::get('folder_id', 0);
$files = DB::table('file')
->where('parent_id', $folder_id)
->where('folder', 0)
->orderBy('created_at', 'desc')
->paginate();
$folders = DB::table('file')
->orderBy('created_at', 'desc')
->paginate();
$rows = [
'name' => '公共网盘', 'type' => '',
'name' => '公共网盘',
'name' => '公共网盘',
];
return $this->display([
'rows' => $rows,
]);
}
public function downAction()
{
$id = (int) Request::get('id', 0);
$row = DB::table('file')->where('id', $id)->first();
if (empty($row)) {
return $this->error('附件不存在。');
}
$name = empty($row['path']) ? 'file/'.$row['name'] : $row['path'].'/'.$row['name'];
$downfile = upload_path($name);
if (is_file($downfile)) {
//打开文件
$filename = mb_convert_encoding($row['title'], "gbk", "UTF-8");
$file = fopen($downfile, "r");
DB::table('download')->where('id', $id)->increment('hits');
//输入文件标签
Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
Header("Accept-Length: " . filesize($downfile));
Header("Content-Disposition: attachment; filename=" . $filename);
//输出文件内容
echo fread($file, filesize($downfile));
fclose($file);
exit;
} else {
return $this->error('附件文件不存在。');
}
}
public function deleteAction()
{
if (Request::method() == 'POST') {
$id = (array)Request::get('id');
$rows = DB::table('file')->whereIn('parent_id', $id)->get();
if ($rows->count()) {
return $this->error('文件夹不为空无法删除。');
}
$rows = DB::table('file')->whereIn('id', $id)->get();
foreach ($rows as $row) {
$path = 'file/'.$row['path'];
if (is_file(upload_path($path))) {
unlink(upload_path($path));
}
DB::table('file')->where('id', $row['id'])->delete();
}
}
return $this->success('index', '删除成功。');
}
}
@@ -0,0 +1,152 @@
<?php namespace Gdoo\File\Controllers;
use Gdoo\Index\Controllers\DefaultController;
use DB;
use Request;
use Validator;
use Gdoo\Model\Grid;
use Gdoo\File\Models\InspectReport;
class InspectReportController extends DefaultController
{
public function indexAction()
{
$header = Grid::header([
'code' => 'file_inspect_report',
'referer' => 1,
'search' => [],
]);
$cols = $header['cols'];
$cols['actions']['options'] = [[
'name' => '下载',
'action' => 'download',
'display' => 1,
]];
$search = $header['search_form'];
$query = $search['query'];
if (Request::method() == 'POST') {
$model = DB::table($header['table'])->setBy($header);
foreach ($header['join'] as $join) {
$model->leftJoin($join[0], $join[1], $join[2], $join[3]);
}
$model->orderBy($header['sort'], $header['order']);
foreach ($search['where'] as $where) {
if ($where['active']) {
$model->search($where);
}
}
$model->select($header['select']);
$rows = $model->paginate($query['limit'])->appends($query);
$items = Grid::dataFilters($rows, $header, function($item) {
$item['size'] = human_filesize($item['size']);
return $item;
});
return $items->toJson();
}
$header['buttons'] = [
['name' => '删除', 'icon' => 'fa-remove', 'action' => 'delete', 'display' => $this->access['delete']],
];
$header['cols'] = $cols;
$header['tabs'] = InspectReport::$tabs;
$header['bys'] = InspectReport::$bys;
$header['js'] = Grid::js($header);
return $this->display([
'header' => $header,
]);
}
public function createAction()
{
if (Request::method() == 'POST') {
$file = Request::file('file');
$name = Request::get('name');
$mime_type = $this->setting['upload_type'];
$validator = Validator::make(
['file' => $file, 'name' => $name],
['file' => 'mimes:'.$mime_type, 'name' => 'required']
);
if ($validator->passes()) {
$path = 'inspect_report/'.date('Y/m');
$upload_path = upload_path().'/'.$path;
// 扩展名称
$extension = $file->getClientOriginalExtension();
// 附件新名字
$filename = date('dhis_').str_random(4).'.'.$extension;
$filename = mb_strtolower($filename);
$uploadSuccess = $file->move($upload_path, $filename);
if ($uploadSuccess) {
// 数据库写入
$draft = new InspectReport;
//$draft->name = mb_strtolower($file->getClientOriginalName());
$draft->name = $name;
$draft->path = $path.'/'.$filename;
$draft->type = $extension;
$draft->size = $file->getClientSize();
$draft->save();
return $this->json('文件上传成功。', true);
}
} else {
return $this->json($validator->errors()->first());
}
return $this->json('文件不能为空。');
}
return $this->render();
}
public function downloadAction()
{
$id = (int) Request::get('id', 0);
$row = DB::table('file_inspect_report')->where('id', $id)->first();
if (empty($row)) {
return $this->error('附件不存在。');
}
$filename = upload_path($row['path']);
if (is_file($filename)) {
// 打开文件
$name = mb_convert_encoding($row['name'], "gbk", "UTF-8");
$file = fopen($filename, "r");
DB::table('file_inspect_report')->where('id', $id)->increment('hits');
// 输入文件标签
Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
Header("Accept-Length: " . filesize($filename));
Header("Content-Disposition: attachment; filename=" . $name.'.'.$row['type']);
// 输出文件内容
echo fread($file, filesize($filename));
fclose($file);
exit;
} else {
return $this->error('附件文件不存在。');
}
}
public function deleteAction()
{
$id = (array)Request::get('id');
$rows = DB::table('file_inspect_report')->whereIn('id', $id)->get();
if ($rows->isEmpty()) {
return $this->json('附件不存在。');
} else {
foreach($rows as $row) {
$path = upload_path($row['path']);
if (is_file($path)) {
unlink($path);
}
DB::table('file_inspect_report')->where('id', $row['id'])->delete();
}
}
return $this->json('文件删除成功。', true);
}
}
@@ -0,0 +1,111 @@
<?php namespace Gdoo\File\Controllers;
use Request;
use URL;
use Gdoo\Index\Controllers\Controller;
class WidgetController extends Controller
{
public $permission = ['index', 'download'];
public $rows = [/*[
'title' => '盛华管理手机客户端',
'date' => '2018-04-09',
'android_url' => '/uploads/com.shenghua.oa/1.0.12.apk',
'ios_url' => ''
],[
'title' => '盛华市场手机客户端',
'date' => '2018-04-07',
'android_url' => '/uploads/com.shenghua.customer/1.0.3.apk',
'ios_url' => '/uploads/com.shenghua.customer/1.0.3.ipa'
],*/[
'title' => '身份验证器(GoogleAuthenticator)',
'date' => '2015-06-17',
'android_url' => '/uploads/android/authenticator2_21.apk',
'ios_url' => ''
],[
'title' => '日历同步助手(Caldav)',
'date' => '2017-06-29',
'android_url' => '/uploads/android/calendar.caldav.sync.apk',
'ios_url' => ''
]];
public function downloadAction()
{
$key = Request::get('key');
$row = $this->rows[$key];
$file = '';
if (get_device_type() == 'ios') {
if ($row['ios_url']) {
$file = url($row['ios_url']);
}
$img = '/assets/images/ios_download.png';
} else {
if ($row['android_url']) {
$file = url($row['android_url']);
}
$img = '/assets/images/android_download.png';
}
if (is_weixin()) {
echo '<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title></title>
<style>
img {
width: 100%;
height: 100%;
}
body {
background-color:#a2a2a2;
}
</style>
</head>
<body>
<div>
<img src="'.$img.'" />
</div>
</body>
</html>';
} else {
if ($file) {
echo "<form action='".$file."' id='go' method='GET'></form><script type='text/javascript'>document.getElementById('go').submit();</script>";
}
}
}
public function indexAction()
{
if (Request::isJson()) {
foreach ($this->rows as $k => &$row) {
$url = '';
if ($row['android_url']) {
$url .= '<a class="option" href="'.url($row['android_url']).'"><i class="fa fa-fw fa-android"></i></a>';
}
if ($row['ios_url']) {
$url .= ' <a class="option" href="'.url($row['ios_url']).'"><i class="fa fa-fw fa-apple"></i></a>';
} else {
$url .= ' <span class="text-muted" href="javascript:;"><i class="fa fa-fw fa-apple"></i></span>';
}
$qrcodeURL = url('index/api/qrcode', ['size' => 6, 'data' => url('file/widget/download', ['key' => $k])]);
$url .= ' <a class="option" href="javascript:;" onclick=\'$.messager.alert("'.$row['title'].'","<div align=\"center\"><img src=\"'.$qrcodeURL.'\"></div>");\'><i class="fa fa-fw fa-qrcode"></i></a>';
$row['option'] = $url;
}
$json['total'] = sizeof($this->rows);
$json['data'] = $this->rows;
return response()->json($json);
}
return $this->render();
}
}