Skip to content

Commit 67acb71

Browse files
committed
修复[bug]#1,配置文件进行了重要调整,本地进行local和s3确认测试
1 parent 9b29c56 commit 67acb71

File tree

5 files changed

+109
-34
lines changed

5 files changed

+109
-34
lines changed

readme.md

+30-2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ php artisan vendor:publish --provider="Zhangmazi\Ueditor\UeditorServiceProivder"
5050
#### 1.配置config/zhangmazi/filesystem.php
5151

5252
请根据注释填写,特别要注意root和url_root,这个2个很关键,因为直接导致你是否能上传成功和是否能正常开放预览附件; root的物理路径一定有0755或者0777(当需要建立子目录时)权限.
53+
[version 1.0.5]这次更新主要是配置调整,所以重要操作,请将disks节点数组复制到config/filesystem.php内的disks内,并注意如果启用S3驱动,root一定要是null
5354

5455
#### 2.配置config/zhangmazi/ueditor.php
5556

@@ -63,9 +64,13 @@ php artisan vendor:publish --provider="Zhangmazi\Ueditor\UeditorServiceProivder"
6364

6465
### Demo使用
6566

66-
开发此包时, 为了增加体验感, 特为大家准备了demo.
67+
开发此包时, 为了增加体验感, 特为大家准备了demo. 启用内置服务运行命令
6768

68-
访问 [http://localhost/zhangmazi/ueditor/demo/index](http://localhost/zhangmazi/ueditor/demo/index), 其中localhost跟更改为你自己的绑定的域名.
69+
```shell
70+
php artisan serve --host=0.0.0.0 --port=8030
71+
```
72+
73+
访问 [http://localhost:8030/zhangmazi/ueditor/demo/index](http://localhost:8030/zhangmazi/ueditor/demo/index), 其中localhost跟更改为你自己的绑定的域名.
6974

7075
为了安全性, 在[.env]文件中APP_DEBUG=true才能使用demo,否则无法访问以上demo相关路由地址.
7176

@@ -152,6 +157,29 @@ class CustomUeditorController extends Controller
152157
{
153158
return 'uploads/ueditor';
154159
}
160+
161+
/**
162+
* 获取保存根目录路径
163+
* @paraam string $driver_name 驱动名
164+
* @return string
165+
*/
166+
protected function getSaveRootPath($driver_name = 'local')
167+
{
168+
return storage_path('app/ueditor');
169+
}
170+
171+
/**
172+
* 删除原始文件
173+
* @param $file
174+
* @return bool
175+
*/
176+
protected function deleteOriginFile($file)
177+
{
178+
File::delete($file['file_native_path']);
179+
File::delete($file['origin_pic_native_path']);
180+
181+
return true;
182+
}
155183
}
156184

157185
?>

src/UeditorUploaderAbstract.php

+31-26
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
* @author ninja911<[email protected]>
66
* @date 2016-08-20 22:35
77
*/
8-
98
namespace Zhangmazi\Ueditor;
109

11-
use Illuminate\Support\Facades\Storage;
12-
use Illuminate\Support\Facades\File;
10+
use Storage;
11+
use File;
12+
use Log;
1313

1414
trait UeditorUploaderAbstract
1515
{
@@ -106,7 +106,7 @@ protected function getStorageConfig()
106106
{
107107
$c1 = config('zhangmazi.filesystems', []);
108108
$c2 = config('filesystems', []);
109-
$c2['disks'] = array_merge($c2['disks'], $c1['disks']);
109+
$c2['ueditor_disk_name'] = $c1['ueditor_disk_name'];
110110
return array_merge($c1, $c2);
111111
}
112112

@@ -208,34 +208,22 @@ protected function uploadFile($upload_field_name = 'upload_files')
208208
$storage_driver = $storage_config['disks'][$disk_name]['driver'];
209209
$save_root_path = $this->getSaveRootPath($storage_driver);
210210
$relative_dir = $this->getRelativeDir();
211-
$visibility = !empty($storage_config[$disk_name]['visibility']) ?
212-
$storage_config[$disk_name]['visibility'] : null;
213-
$url_root = !empty($storage_config[$disk_name]['url_root']) ?
214-
trim($storage_config[$disk_name]['url_root'], '/') : '';
215-
if ($storage_driver != 'local') {
216-
$upload_path = '';
217-
} else {
218-
$upload_path = $save_root_path;
219-
}
211+
$visibility = !empty($storage_config['disks'][$disk_name]['visibility']) ?
212+
$storage_config['disks'][$disk_name]['visibility'] : null;
213+
$url_root = $storage_config['disks'][$disk_name]['url_root'];
220214
foreach ($arr_files as $file) {
221215
$res = $uploader->uploadFile($file, $save_root_path, $relative_dir);
222216
if (!empty($res[0]['file_size'])) {
223-
if ($this->getStorage()->put(
224-
$upload_path . '/' .$res[0]['file_path'],
217+
$img_url = $relative_dir . '/'. $res[0]['file_name'];
218+
if (File::exists($res[0]['file_native_path']) && $this->getStorage()->put(
219+
$img_url,
225220
File::get($res[0]['file_native_path']),
226221
$visibility
227222
)) {
228-
$res[0]['link_url'] = $url_root . '/' . $res[0]['file_path'];
223+
$res[0]['link_url'] = $url_root . $img_url;
229224
$arr_return[] = $res[0];
230-
if ($storage_driver == 'local') {
231-
if (File::exists($res[0]['file_native_path'])) {
232-
File::delete($res[0]['file_native_path']);
233-
}
234-
if (!empty($res[0]['origin_pic_native_path']) &&
235-
File::exists($res[0]['origin_pic_native_path'])) {
236-
File::delete($res[0]['origin_pic_native_path']);
237-
}
238-
}
225+
//删除原始文件
226+
$this->deleteOriginFile($res[0]);
239227
//写入DB记录
240228
$this->insertRecord($res[0], $request);
241229
} else {
@@ -246,6 +234,7 @@ protected function uploadFile($upload_field_name = 'upload_files')
246234
}
247235
}
248236
}
237+
249238
return $arr_return;
250239
}
251240

@@ -501,6 +490,10 @@ protected function getJsonConfig()
501490
'catcherLocalDomain' => array(
502491
'127.0.0.1',
503492
'localhost',
493+
'static.oschina.net',
494+
'127.net',
495+
'cms-bucket.nosdn.127.net',
496+
'blog.ninja911.com'
504497
),
505498
'catcherActionName' => 'CatchImage', //执行抓取远程图片的action名称
506499
'catcherFieldName' => $upload_field_name, //提交的图片列表表单名称
@@ -615,7 +608,19 @@ protected function getSaveRootPath($driver_name = 'local')
615608
{
616609
$disk_name = $this->getStorageDiskName();
617610
$storage_config = $this->getStorageConfig();
618-
return $driver_name != 'local' ? storage_path('app/public/ueditor/tmp') :
611+
return $driver_name != 'local' ? storage_path('app/ueditor/tmp') :
619612
$storage_config['disks'][$disk_name]['root'];
620613
}
614+
615+
/**
616+
* 删除原始图片
617+
* @param $file
618+
* @return bool
619+
*/
620+
protected function deleteOriginFile($file)
621+
{
622+
File::delete($file['file_native_path']);
623+
File::delete($file['origin_pic_native_path']);
624+
return true;
625+
}
621626
}

src/Uploader.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace Zhangmazi\Ueditor;
1010

1111
use Illuminate\Support\Facades\File;
12+
use Log;
1213

1314
class Uploader
1415
{
@@ -176,6 +177,7 @@ function ($constraint) use ($thumb_appointed) {
176177
'origin_pic_height' => 0,
177178
];
178179
}
180+
179181
return $lists;
180182
}
181183

@@ -268,7 +270,7 @@ public function check($file_ext, $file_size, $file_mime)
268270
public function initSaveLocalDir($save_root_path, $relative_dir)
269271
{
270272
$path = empty($save_root_path) ? storage_path('app/public/ueditor/tmp') : $save_root_path;
271-
if (empty($relative_dir)) {
273+
if (!empty($relative_dir)) {
272274
$path .= '/'. $relative_dir;
273275
}
274276
if (!File::isDirectory($path)) {

src/config/zhangmazi/filesystems.php

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* 描述.
3+
* 文件存储配置.
44
*
55
* @author ninja911<[email protected]>
66
* @date 2016-08-21 06:47
@@ -9,10 +9,20 @@
99
'disks' => [
1010
'public_attachment' => [
1111
'driver' => 'local', //驱动类型,local=本地,s3=亚马逊,当然可以Stoarge::extend扩展比如七牛类似的第三方服务
12-
'root' => public_path(), //文件存储的本地物理根目录
12+
'root' => storage_path('app/'), //文件存储的本地物理根目录, 如果是S3驱动,请设置为null值
1313
'visibility' => null, //对外可视,比如亚马逊S3服务,这里就会填写public,一般本地local,填写null即可
14-
'url_root' => '', //项目附件服务器URL根,如果是第三方比如S3等,请在默认项目目录config下,填写补充这个url_root
14+
'url_root' => '/', //项目附件服务器URL根,如果是第三方比如S3等,请在默认项目目录config下,填写补充这个url_root
15+
],
16+
'china_s3' => [
17+
'driver' => 's3', //驱动类型,local=本地,s3=亚马逊,当然可以Stoarge::extend扩展比如七牛类似的第三方服务
18+
'root' => null, //文件存储的本地物理根目录, 如果是S3驱动,请设置为null值
19+
'visibility' => 'public', //对外可视,比如亚马逊S3服务,这里就会填写public,一般本地local,填写null即可
20+
'url_root' => '//s3.cn-north-1.amazonaws.com.cn/hellophp/', //项目附件服务器URL根,如果是第三方比如S3等,请在默认项目目录config下,填写补充这个url_root
21+
'key' => '',
22+
'secret' => '',
23+
'region' => 'cn-north-1',
24+
'bucket' => '',
1525
],
1626
],
1727
'ueditor_disk_name' => 'public_attachment', // 百度编辑器所使用的文件磁盘名, 这个定义名必须包含在filesystems.php配置[disks]节点里
18-
];
28+
];

src/views/ueditorDemoIndex.blade.php

+31-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
<h3>配置</h3>
6060
<h4>1.配置config/zhangmazi/filesystem.php</h4>
6161
<p>请根据注释填写,特别要注意root和url_root,这个2个很关键,因为直接导致你是否能上传成功和是否能正常开放预览附件; root的物理路径一定有0755或者0777(当需要建立子目录时)权限.</p>
62+
<p>[version 1.0.5]这次更新主要是配置调整,所以重要操作,请将disks节点数组复制到config/filesystem.php内的disks内,并注意如果启用S3驱动,root一定要是null</p>
6263
<h4>2.配置config/zhangmazi/ueditor.php</h4>
6364
<p>请根据注释填写,节点[routes]支持多组应用场景,其配置其实就Laravel的Route原生配置方法; 其中带有"group_"前缀的都不填,将不使用路由组模式; 如果"via_integrate"为true,将使用内置命名空间,同时不要修改"uses".</p>
6465
<h4>3.配置config/zhangmazi/ext2mime.php</h4>
@@ -71,7 +72,10 @@
7172
<div class="row">
7273
<h3>Demo使用</h3>
7374
<p>开发此包时, 为了增加体验感, 特为大家准备了demo.</p>
74-
<p>访问 <a href="http://localhost/zhangmazi/ueditor/demo/index">http://localhost/zhangmazi/ueditor/demo/index</a>, 其中localhost跟更改为你自己的绑定的域名.</p>
75+
<p>
76+
<pre>php artisan serve --host=0.0.0.0 --port=8030</pre>
77+
</p>
78+
<p>访问 <a href="http://localhost:8030/zhangmazi/ueditor/demo/index">http://localhost:8030/zhangmazi/ueditor/demo/index</a>, 其中localhost跟更改为你自己的绑定的域名.</p>
7579
<p>为了安全性, 在[.env]文件中APP_DEBUG=true才能使用demo,否则无法访问以上demo相关路由地址.</p>
7680
</div>
7781
<div class="row">
@@ -141,6 +145,29 @@ protected function getRelativeDir()
141145
{
142146
return 'uploads/ueditor';
143147
}
148+
149+
/**
150+
* 获取保存根目录路径
151+
* @paraam string $driver_name 驱动名
152+
* @return string
153+
*/
154+
protected function getSaveRootPath($driver_name = 'local')
155+
{
156+
return storage_path('app/ueditor');
157+
}
158+
159+
/**
160+
* 删除原始文件
161+
* @param $file
162+
* @return bool
163+
*/
164+
protected function deleteOriginFile($file)
165+
{
166+
File::delete($file['file_native_path']);
167+
File::delete($file['origin_pic_native_path']);
168+
169+
return true;
170+
}
144171
}
145172

146173
?&gt;</pre>
@@ -233,6 +260,7 @@ function getUeditorCommonParams() {
233260
'autoHeightEnabled' : false,
234261
'pageBreakTag' : 'editor_page_break_tag',
235262
'maximumWords' : 1000000, //自定义可以输入多少字
263+
'autoFloatEnabled' : false,
236264
'initialFrameWidth' : "100%",
237265
'initialFrameHeight' : ueditor_height
238266
});
@@ -261,6 +289,7 @@ function getUeditorCommonParams() {
261289
'pageBreakTag' : 'editor_page_break_tag',
262290
'maximumWords' : 1000000, //自定义可以输入多少字
263291
'toolbars' : ueditor_toolbars, //采用自定义工具条
292+
'autoFloatEnabled' : false,
264293
'initialFrameWidth' : 600, //自定义高度
265294
'initialFrameHeight' : 300 //自定义高度
266295
});
@@ -278,6 +307,7 @@ function getUeditorCommonParams() {
278307
'autoHeightEnabled' : false,
279308
'pageBreakTag' : 'editor_page_break_tag',
280309
'maximumWords' : 1000000, //自定义可以输入多少字
310+
'autoFloatEnabled' : false,
281311
'initialFrameWidth' : "100%",
282312
'initialFrameHeight' : ueditor_height
283313
});

0 commit comments

Comments
 (0)