Browse Source

move dir improve, to support root directory

master
filesite 2 years ago
parent
commit
3ed89fb496
  1. 38
      controller/ApiController.php
  2. 1
      controller/Controller.php
  3. 2
      www/content/README.md

38
controller/ApiController.php

@ -49,9 +49,11 @@ Class ApiController extends Controller {
} }
private function getParentDir($realpath) { private function getParentDir($realpath) {
if ($realpath == '/') {return $realpath;}
$realpath = preg_replace('/\/$/', '', $realpath); $realpath = preg_replace('/\/$/', '', $realpath);
$arr = explode('/', $realpath); $arr = explode('/', $realpath);
if (count($arr) < 2) {return $realpath;} if (count($arr) < 2) {return '/';}
array_pop($arr); array_pop($arr);
return implode('/', $arr); return implode('/', $arr);
@ -61,6 +63,8 @@ Class ApiController extends Controller {
protected function isParentDirectoryValid($parentDir) { protected function isParentDirectoryValid($parentDir) {
if (empty($parentDir) || strpos($parentDir, '../') !== false) { if (empty($parentDir) || strpos($parentDir, '../') !== false) {
return false; return false;
}else if ($realpath == '/') {
return true;
} }
$valid = true; $valid = true;
@ -288,7 +292,17 @@ Class ApiController extends Controller {
$target = __DIR__ . '/../www/' . FSC::$app['config']['content_directory']; $target = __DIR__ . '/../www/' . FSC::$app['config']['content_directory'];
try { try {
//兼容已经存在的目录,则移动进去,而不是重命名
if ($toDir == '/') {
$basename = $this->basename($fromDir);
$res = rename("{$target}/{$fromDir}", "{$target}/{$basename}");
}else if (!realpath("{$target}/{$toDir}")) {
$res = rename("{$target}/{$fromDir}", "{$target}/{$toDir}"); $res = rename("{$target}/{$fromDir}", "{$target}/{$toDir}");
}else {
$basename = $this->basename($fromDir);
$res = rename("{$target}/{$fromDir}", "{$target}/{$toDir}/{$basename}");
}
if ($res) { if ($res) {
$code = 1; $code = 1;
$msg = '目录/文件移动完成'; $msg = '目录/文件移动完成';
@ -340,9 +354,9 @@ Class ApiController extends Controller {
$res = rename("{$target}/{$fromDir}", "{$target}/{$toDir}"); $res = rename("{$target}/{$fromDir}", "{$target}/{$toDir}");
if ($res) { if ($res) {
$code = 1; $code = 1;
$msg = '目录移动完成'; $msg = '重命名完成';
}else { }else {
$err = '目录移动失败,请确认被移动目录存在及目标目录权限配置正确!'; $err = '重命名失败,请确认被重命名目录/文件存在及目标目录权限配置正确!';
} }
}catch(Exception $e) { }catch(Exception $e) {
$err = $e->getMessage(); $err = $e->getMessage();
@ -409,7 +423,8 @@ Class ApiController extends Controller {
$refresh = (int)$this->post('refresh', 0); $refresh = (int)$this->post('refresh', 0);
try { try {
$builder = new CaptchaBuilder; $randNumber = rand(10000, 99999);
$builder = new CaptchaBuilder("{$randNumber}");
$builder->build(); $builder->build();
$captcha_jpg = $builder->get(); $captcha_jpg = $builder->get();
$captcha_code = $builder->getPhrase(); $captcha_code = $builder->getPhrase();
@ -724,6 +739,21 @@ Class ApiController extends Controller {
if (!empty($contentDirectory)) { if (!empty($contentDirectory)) {
$jsonData['content_directory'] = $contentDirectory; $jsonData['content_directory'] = $contentDirectory;
}else {
switch($themeName) {
case 'manual':
$jsonData['content_directory'] = 'content';
break;
case 'webdirectory':
$jsonData['content_directory'] = 'navs';
break;
case 'googleimage':
$jsonData['content_directory'] = 'girls';
break;
case 'videoblog':
$jsonData['content_directory'] = 'videos';
break;
}
} }
if (file_exists($customConfigFile)) { if (file_exists($customConfigFile)) {

1
controller/Controller.php

@ -279,6 +279,7 @@ Class Controller {
//get basename of realpath, support chinese //get basename of realpath, support chinese
protected function basename($realpath) { protected function basename($realpath) {
$realpath = preg_replace('/\/$/', '', $realpath);
$arr = explode('/', $realpath); $arr = explode('/', $realpath);
if (count($arr) < 2) {return $realpath;} if (count($arr) < 2) {return $realpath;}

2
www/content/README.md

@ -131,7 +131,7 @@ http://127.0.0.1:1080
FileSite.io官方提供的皮肤都包含在最新版的源码目录```themes/```中,详情如下: FileSite.io官方提供的皮肤都包含在最新版的源码目录```themes/```中,详情如下:
| 皮肤名称 | 目录 | 适用网站类型 | | 皮肤名称 | 皮肤目录 | 适用网站类型 |
| ---- | ---- | ---- | | ---- | ---- | ---- |
| WebDirectory | webdirectory | 导航站 | | WebDirectory | webdirectory | 导航站 |
| Manual | manual | 文档站 | | Manual | manual | 文档站 |

Loading…
Cancel
Save