fixed filemanager
This commit is contained in:
parent
be69a68a08
commit
cfe1e6d987
|
|
@ -25,4 +25,61 @@ class FileManagerController extends Controller
|
||||||
|
|
||||||
return view('admin::pages.file_manager.index', $data);
|
return view('admin::pages.file_manager.index', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建文件夹
|
||||||
|
* POST /admin/file_manager
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function store(Request $request): array
|
||||||
|
{
|
||||||
|
$folderName = $request->get('name');
|
||||||
|
(new FileManagerService)->createDirectory($folderName);
|
||||||
|
return json_success('创建成功');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除文件或文件夹
|
||||||
|
* DELETE /admin/file_manager/{file_manager}
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function destroy(Request $request): array
|
||||||
|
{
|
||||||
|
$folderName = $request->get('name');
|
||||||
|
(new FileManagerService)->deleteDirectoryOrFile($folderName);
|
||||||
|
return json_success('删除成功');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件或文件夹改名
|
||||||
|
* PUT /admin/file_manager/{file_manager}
|
||||||
|
*/
|
||||||
|
public function update(Request $request)
|
||||||
|
{
|
||||||
|
$folderName = $request->get('name');
|
||||||
|
(new FileManagerService)->updateName($folderName);
|
||||||
|
return json_success('删除成功');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传文件
|
||||||
|
* POST /admin/file_manager/upload
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function uploadFiles(Request $request): array
|
||||||
|
{
|
||||||
|
$file = $request->file('file');
|
||||||
|
$path = $file->store('xxx', 'upload');
|
||||||
|
|
||||||
|
return [
|
||||||
|
'name' => $file->getClientOriginalName(),
|
||||||
|
'url' => asset('upload/' . $path),
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,15 +22,15 @@ class AdminServiceProvider extends ServiceProvider
|
||||||
*/
|
*/
|
||||||
public function boot()
|
public function boot()
|
||||||
{
|
{
|
||||||
$uri = request()->getRequestUri();
|
|
||||||
load_settings();
|
load_settings();
|
||||||
|
$this->loadRoutesFrom(__DIR__ . '/../Routes/admin.php');
|
||||||
|
|
||||||
|
$uri = request()->getRequestUri();
|
||||||
$adminName = admin_name();
|
$adminName = admin_name();
|
||||||
if (!Str::startsWith($uri, "/{$adminName}")) {
|
if (!Str::startsWith($uri, "/{$adminName}")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->loadRoutesFrom(__DIR__ . '/../Routes/admin.php');
|
|
||||||
$this->mergeConfigFrom(__DIR__ . '/../../Config/beike.php', 'beike');
|
$this->mergeConfigFrom(__DIR__ . '/../../Config/beike.php', 'beike');
|
||||||
$this->loadViewsFrom(resource_path('/beike/admin/views'), 'admin');
|
$this->loadViewsFrom(resource_path('/beike/admin/views'), 'admin');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ Route::prefix($adminName)
|
||||||
Route::Resource('files', \Beike\Admin\Http\Controllers\FileController::class);
|
Route::Resource('files', \Beike\Admin\Http\Controllers\FileController::class);
|
||||||
|
|
||||||
Route::Resource('file_manager', \Beike\Admin\Http\Controllers\FileManagerController::class);
|
Route::Resource('file_manager', \Beike\Admin\Http\Controllers\FileManagerController::class);
|
||||||
|
Route::post('file_manager/upload', [\Beike\Admin\Http\Controllers\FileManagerController::class, 'uploadFiles'])->name('file_manager.upload');
|
||||||
|
|
||||||
Route::Resource('customers', \Beike\Admin\Http\Controllers\CustomerController::class);
|
Route::Resource('customers', \Beike\Admin\Http\Controllers\CustomerController::class);
|
||||||
Route::resource('customers.addresses', \Beike\Admin\Http\Controllers\AddressController::class);
|
Route::resource('customers.addresses', \Beike\Admin\Http\Controllers\AddressController::class);
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,46 @@ class FileManagerService
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建目录
|
||||||
|
* @param $folderName
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function createDirectory($folderName)
|
||||||
|
{
|
||||||
|
$folderPath = public_path("catalog/{$folderName}");
|
||||||
|
if (is_dir($folderPath)) {
|
||||||
|
throw new \Exception("目录已存在");
|
||||||
|
}
|
||||||
|
createDirectories(dirname($folderName));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $filePath
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function deleteDirectoryOrFile($filePath)
|
||||||
|
{
|
||||||
|
$filePath = public_path("catalog/{$filePath}");
|
||||||
|
if (is_dir($filePath)) {
|
||||||
|
$files = glob($filePath . '/*');
|
||||||
|
if ($files) {
|
||||||
|
throw new \Exception("该目录不为空");
|
||||||
|
}
|
||||||
|
@rmdir($filePath, 0755);
|
||||||
|
} elseif (file_exists($filePath)) {
|
||||||
|
@unlink($filePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function updateName()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理文件夹
|
* 处理文件夹
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Beike\Models\Setting;
|
|
||||||
use Beike\Models\Customer;
|
use Beike\Models\Customer;
|
||||||
use Beike\Models\AdminUser;
|
use Beike\Models\AdminUser;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
@ -237,18 +236,34 @@ function json_fail($message, $data = []): array
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!function_exists('to_sql')) {
|
/**
|
||||||
/**
|
* 根据 $builder 对象输出SQL语句
|
||||||
* @param mixed $builder
|
* @param mixed $builder
|
||||||
* @return string|string[]|null
|
* @return string|string[]|null
|
||||||
*/
|
*/
|
||||||
function to_sql($builder)
|
function to_sql($builder)
|
||||||
{
|
{
|
||||||
$sql = $builder->toSql();
|
$sql = $builder->toSql();
|
||||||
foreach ($builder->getBindings() as $binding) {
|
foreach ($builder->getBindings() as $binding) {
|
||||||
$value = is_numeric($binding) ? $binding : "'" . $binding . "'";
|
$value = is_numeric($binding) ? $binding : "'" . $binding . "'";
|
||||||
$sql = preg_replace('/\?/', $value, $sql, 1);
|
$sql = preg_replace('/\?/', $value, $sql, 1);
|
||||||
}
|
}
|
||||||
return $sql;
|
return $sql;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 递归创建文件夹
|
||||||
|
* @param $directoryPath
|
||||||
|
*/
|
||||||
|
function createDirectories($directoryPath)
|
||||||
|
{
|
||||||
|
$path = '';
|
||||||
|
$directories = explode('/', $directoryPath);
|
||||||
|
foreach ($directories as $directory) {
|
||||||
|
$path = $path . '/' . $directory;
|
||||||
|
if (!is_dir(public_path($path))) {
|
||||||
|
@mkdir(public_path($path), 0755);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ class ImageService
|
||||||
|
|
||||||
$newImagePath = public_path($newImage);
|
$newImagePath = public_path($newImage);
|
||||||
if (!is_file($newImagePath) || (filemtime($this->imagePath) > filemtime($newImagePath))) {
|
if (!is_file($newImagePath) || (filemtime($this->imagePath) > filemtime($newImagePath))) {
|
||||||
$this->createDirectories($newImage);
|
createDirectories(dirname($newImage));
|
||||||
$img = Image::make($this->imagePath);
|
$img = Image::make($this->imagePath);
|
||||||
|
|
||||||
$img->resize($width, $height, function ($constraint) {
|
$img->resize($width, $height, function ($constraint) {
|
||||||
|
|
@ -61,22 +61,4 @@ class ImageService
|
||||||
}
|
}
|
||||||
return asset($newImage);
|
return asset($newImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 递归创建缓存文件夹
|
|
||||||
*
|
|
||||||
* @param $imagePath
|
|
||||||
*/
|
|
||||||
private function createDirectories($imagePath)
|
|
||||||
{
|
|
||||||
$path = '';
|
|
||||||
$directories = explode('/', dirname($imagePath));
|
|
||||||
foreach ($directories as $directory) {
|
|
||||||
$path = $path . '/' . $directory;
|
|
||||||
if (!is_dir(public_path($path))) {
|
|
||||||
@mkdir(public_path($path), 0755);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue