Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CKEditor Laravel图像上传未定义_Laravel_Ckeditor - Fatal编程技术网

CKEditor Laravel图像上传未定义

CKEditor Laravel图像上传未定义,laravel,ckeditor,Laravel,Ckeditor,我正在尝试使用CKEditor和Laravel7来编辑富文本。但是,图像上载不起作用。 我已在线搜索解决方案,他们建议使用: config.filebrowserUploadMethod='form'; 但添加这一行并不能解决我的问题 我得到一个“未定义”和“服务器错误” 这是我的密码 config.js config.removeDialogTabs = 'image:advanced;link:advanced'; config.removePlugins = 'image'

我正在尝试使用CKEditor和Laravel7来编辑富文本。但是,图像上载不起作用。 我已在线搜索解决方案,他们建议使用: config.filebrowserUploadMethod='form'; 但添加这一行并不能解决我的问题

我得到一个“未定义”和“服务器错误” 这是我的密码 config.js

    config.removeDialogTabs = 'image:advanced;link:advanced';
    config.removePlugins = 'image'; //I had previous conflict between easyimage and image that's why I added this
    config.height = 700;
    config.filebrowserUploadMethod = 'form';
遥控器

 public function upload(Request $request)
    {
        if($request->hasFile('upload')) {
            $originName = $request->file('upload')->getClientOriginalName();
            $fileName = pathinfo($originName, PATHINFO_FILENAME);
            $extension = $request->file('upload')->getClientOriginalExtension();
            $fileName = $fileName.'_'.time().'.'.$extension;

            $request->file('upload')->move(public_path('images'), $fileName);

            $CKEditorFuncNum = $request->input('CKEditorFuncNum');
            $url = asset('images/'.$fileName);
            $msg = 'Image uploaded successfully';
            // answers online suggested to use this instead of section below but it gave me undifined error
            return response()->json([ 'fileName' => $fileName, 'uploaded' => false, 'url' => $url, $msg ]);

            //previously the section below gave me an error of server
           // $response = "<script>window.parent.CKEDITOR.tools.callFunction($CKEditorFuncNum, '$url', '$msg')</script>";

          //  @header('Content-type: text/html; charset=utf-8');
           // echo $response;
        }
    }
形式

@extends('layouts.app')

@section('content')

    <div class="row section-primary">
        <div class="col-md-12">
            <div class="dashboard-post-header">
                <h2>Create Post</h2>
                <a href="{{url('/admin/dashboard/')}}" class="btn btn-primary">Dashboard</a>
            </div>


    {!! Form::open(['action' =>  'PostsController@store','method' => 'POST', 'enctype' => 'multipart/form-data']) !!}
    <div class="form-group">
        {{Form::label('title','Title')}}
        {{Form::text('title','',['class'=>'form-control','placeholder'=>'Title'])}}
    </div>
    <div class="form-group">
        {{Form::label('published','Status')}}
        {{Form::select('published', ['0' => 'Draft', '1' => 'Published'])}}
    </div>

    <div class="form-group">
        {{Form::label('type','Type')}}
        {{Form::select('type', ['companies' => 'Companies', 'macro-trends' => 'Macro Trends'])}}
    </div>




    <div class="form-group">
        {{Form::label('content_preview','Cotent Preview')}}
        {{Form::textarea('content_preview','',['class'=>'form-control','placeholder'=>'Content Preview'])}}
    </div>
    <div class="form-group">
        {{Form::label('content','Content')}}
        {{Form::textarea('content','',['id'=>'article-ckeditor','placeholder'=>'Content'])}}
    </div>

    <div class="form-group">
        {{Form::file('image')}}
    </div>

    <div id="editorjs"></div>

    {{Form::submit('Submit',['class' => 'btn btn-primary'])}}
    {!! Form::close() !!}


    <script type="text/javascript">
        $(document).ready(function () {
            CKEDITOR.replace( 'article-ckeditor', {
                filebrowserUploadUrl: "{{route('upload', ['_token' => csrf_token() ])}}",
                filebrowserUploadMethod: 'form'
            });



        });




    </script>


</div>
    </div>
@endsection
@extends('layouts.app'))
@节(“内容”)
创建帖子
{!!Form::open(['action'=>'PostsController@store“,”方法“=>”POST“,”enctype“=>”多部分/表单数据“])
{{Form::label('title','title')}
{{Form::text('title','',['class'=>'Form-control','placeholder'=>'title'])}
{{Form::label('published','Status')}
{{Form::select('published',['0'=>'草稿','1'=>'published'])}
{{Form::label('type','type')}
{{Form::select('type',['companys'=>'companys','macro trends'=>'macro trends'])}
{{Form::label('content_preview','coent preview')}
{Form::textarea('content_preview','',['class'=>'Form-control','placeholder'=>'content preview'])}
{{Form::label('content','content')}
{Form::textarea('content','',['id'=>'article-ckeditor','placeholder'=>'content'])}
{{Form::file('image')}
{{Form::submit('submit',['class'=>'btn btn primary'])}
{!!Form::close()!!}
$(文档).ready(函数(){
CKEDITOR.replace('article CKEDITOR'{
filebrowserUploadUrl:“{{route('upload',[''U token'=>CSRFUToken())}}”,
filebrowserUploadMethod:“表单”
});
});
@端部
这是我的代码(旧项目),与ckfinder结合使用,效果很好

在刀片中:

<textarea name="content" required aria-required="true" class="ckeditor" id="editor">{{html_entity_decode(old('content'))}}</textarea>
{{html_entity_decode(old('content'))}
javascript:

<script src="{{asset('ckeditor.js')}}"></script>
@include('ckfinder::setup')
CKEDITOR.replace('editor',
{
  filebrowserBrowseUrl: "{{ route('ckfinder_browser', 'Type=Files') }}",
  filebrowserImageBrowseUrl: "{{ route('ckfinder_browser', 'Type=Images') }}",
  filebrowserFlashBrowseUrl: "{{ route('ckfinder_browser', 'Type=Flash') }}",
  filebrowserUploadUrl: "{{ route('ckfinder_connector', 'command=QuickUpload&type=Files') }}",
  filebrowserImageUploadUrl: '{{ route('ckeditor_upload',['_token' => csrf_token() ]) }}',
  filebrowserFlashUploadUrl: "{{ route('ckfinder_connector', 'command=QuickUpload&type=Flash') }}"
});

@包括('ckfinder::setup')
CKEDITOR.replace('editor',
{
filebrowserBrowseUrl:“{{route('ckfinder_browser','Type=Files')}”,
filebrowserImageBrowseUrl:“{{route('ckfinder_browser','Type=Images')}”,
filebrowserFlashBrowseUrl:“{{route('ckfinder_browser','Type=Flash')}”,
filebrowserUploadUrl:“{{route('ckfinder_connector','command=QuickUpload&type=Files')}”,
filebrowserImageUploadUrl:“{route('ckeditor_upload',[''u token'=>csrf_token())}”,
filebrowserFlashUploadUrl:“{{route('ckfinder_connector','command=QuickUpload&type=Flash')}”
});
在控制器中:

use File;
use Illuminate\Support\Str;

public function ckeditor_upload(Request $request)
{
    $funcNum  = $request->input('CKEditorFuncNum');
    $message  = $url = '';
    if ($request->hasFile('upload')) {
        $file = $request->file('upload');
        if ($file->isValid()) {
            $folder = public_path('images/gallery/');
            if(!is_dir($folder)){
                File::makeDirectory($folder, $mode = 0777, true, true);
            }

            $filename = Str::uuid().$file->getClientOriginalExtension();
            $file->move($folder, $filename);
            $url = public_path("images/gallery/{$filename}"); //asset() i guess worked fine
        } 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>";
}
使用文件;
使用light\Support\Str;
公共函数ckeditor_上传(请求$Request)
{
$funcNum=$request->input('CKEditorFuncNum');
$message=$url='';
如果($request->hasFile('upload')){
$file=$request->file('upload');
如果($file->isValid()){
$folder=public_path('images/gallery/');
如果(!is_dir($folder)){
File::makeDirectory($folder,$mode=0777,true,true);
}
$filename=Str::uuid().$file->getClientOriginalExtension();
$file->move($folder,$filename);
$url=public_path(“images/gallery/{$filename}”);///asset()我想效果不错
}否则{
$message='上载文件时出错';
}
}否则{
$message='未上载任何文件';
}
返回“window.parent.CKEDITOR.tools.callFunction({$funcNum},{$url},{$message}”);
}

与我的代码基本相同,我猜在这里,当你将文件移动到未定义文件夹
public\u path(“images”)
它应该是
public\u path(“images/”)
将文件放入images folderit仍然会给我未定义的文件,我的图像正在上载到public\images如果你使用
$request->file('upload')->move(public_path('images'),$fileName);
将失败,因为它不是一个文件夹,它将返回
public\images$fileName
而不是
public\images\$fileName
只要确保你的文件在其中,如果文件夹
public\images
不存在
如果(!is_dir($path)){file::makeDirectory($path,$mode=0777,true,true);}
use File;
use Illuminate\Support\Str;

public function ckeditor_upload(Request $request)
{
    $funcNum  = $request->input('CKEditorFuncNum');
    $message  = $url = '';
    if ($request->hasFile('upload')) {
        $file = $request->file('upload');
        if ($file->isValid()) {
            $folder = public_path('images/gallery/');
            if(!is_dir($folder)){
                File::makeDirectory($folder, $mode = 0777, true, true);
            }

            $filename = Str::uuid().$file->getClientOriginalExtension();
            $file->move($folder, $filename);
            $url = public_path("images/gallery/{$filename}"); //asset() i guess worked fine
        } 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>";
}