图像从ckeditor上传到laravel本地文件系统

时间:2018-05-15 04:43:40

标签: javascript json laravel ckeditor

我试图使用ckeditor将图像上传到laravel中我的本地文件系统,为此我制作了一个正常工作的代码,正确上传所有内容都正常工作,除非在ckeditor中它没有显示链接这里是我的代码:

<script>
  window.onload = function() {
CKEDITOR.replace('long_description', {
 filebrowserUploadUrl: '{{ route('upload',['_token' => csrf_token() ]) }}'   

});

 };</script>

在死记硬背部分,我做了一个上传路线:

Route::post('upload_image','CkeditorController@uploadImage')->name('upload');

在控制器部分我使用此代码:

use Illuminate\Http\Request;

use Illuminate\Support\Facades\Input;



class CkeditorController extends Controller
{
    public function uploadImage(Request $request) {
 $CKEditor = $request->input('CKEditor');
 $funcNum  = $request->input('CKEditorFuncNum');
 $message  = $url = '';
 if (Input::hasFile('upload')) {
 $file = Input::file('upload');
 if ($file->isValid()) {
 $filename =rand(1000,9999).$file->getClientOriginalName();
 $file->move(public_path().'/wysiwyg/', $filename);
 $url = url('wysiwyg/' . $filename);
 } else {
 $message = 'An error occurred while uploading the file.';
 }
 } else {
 $message = 'No file uploaded.';
 }
 return '<script>window.parent.CKEDITOR.tools.callFunction('.$funcNum.', "'.$url.'", "'.$message.'")</script>';
}
}

当我尝试上传上传工作时,精细图像在dir中进行,但在respose中我得到了错误:

[CKEDITOR] Error code: filetools-response-error. {responseText: "<script>window.parent.CKEDITOR.tools.callFunction(…linic/wysiwyg/4121dominospizza.jpg", "")</script>"}

所以我搜索错误,但我没有得到错误说明

An error occurred when parsing the upload response. Text could not be parsed to JSON.
Additional data:
responseText: Upload response text.

请帮助我,请提前致谢。

0 个答案:

没有答案