Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.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
Php Laravel在CKEDITOR上上传图像_Php_Laravel_Laravel 5_Ckeditor - Fatal编程技术网

Php Laravel在CKEDITOR上上传图像

Php Laravel在CKEDITOR上上传图像,php,laravel,laravel-5,ckeditor,Php,Laravel,Laravel 5,Ckeditor,当我使用fromckeditor上传图像并将其附加到控制器中的post上时,我的上传图像功能工作正常,没有任何问题,但当我想将上传的图像返回到该位置时,ckeditor无法获取该图像,例如,这是我的代码: 控制器: public function uploadImageContent() { $this->validate(request(), [ 'upload' => 'mimes:jpeg,jpg,gif,png' ]); $file

当我使用from
ckeditor
上传图像并将其附加到控制器中的post上时,我的上传图像功能工作正常,没有任何问题,但当我想将上传的图像返回到该位置时,ckeditor无法获取该图像,例如,这是我的代码:

控制器:

public function uploadImageContent()
{
    $this->validate(request(), [
        'upload' => 'mimes:jpeg,jpg,gif,png'
    ]);

    $file = request()->file('upload');
    $filename = $file->getClientOriginalName();

    $year = Carbon::now()->year;
    $imagePath = "/uploads/post_images/{$year}/";

    if (file_exists(public_path($imagePath) . $filename)) {
        $filename = Carbon::now()->timestamp . '.' . $filename;
    }

    $file->move(public_path() . $imagePath, $filename);

    $url = $imagePath . $filename;

    return "<script>window.parent.CKEDITOR.tools.callFunction(1,'{$url}','')</script>";
}
class ContentsController extends Controller
{
    ...

    public function attachImage()
    {
        $this->uploadImageContent(request()->all());
    }
}
应该是返回路径,但不工作

视图:

ContentsController:

public function uploadImageContent()
{
    $this->validate(request(), [
        'upload' => 'mimes:jpeg,jpg,gif,png'
    ]);

    $file = request()->file('upload');
    $filename = $file->getClientOriginalName();

    $year = Carbon::now()->year;
    $imagePath = "/uploads/post_images/{$year}/";

    if (file_exists(public_path($imagePath) . $filename)) {
        $filename = Carbon::now()->timestamp . '.' . $filename;
    }

    $file->move(public_path() . $imagePath, $filename);

    $url = $imagePath . $filename;

    return "<script>window.parent.CKEDITOR.tools.callFunction(1,'{$url}','')</script>";
}
class ContentsController extends Controller
{
    ...

    public function attachImage()
    {
        $this->uploadImageContent(request()->all());
    }
}

使用
echo
而不是
return
解决我的问题:

echo "<script>window.parent.CKEDITOR.tools.callFunction(1,'{$url}','')</script>";
echo“window.parent.CKEDITOR.tools.callFunction(1,{$url},''”;

我在laravel 5.5上有这个问题,你的代码对我不起作用。我观察到的是,您没有将
CKEditorFuncNum
(服务器作为POST变量接收)嵌入到
1
的位置,作为
callFunction()
的第一个参数。我用
$request->CKEditorFuncNum
替换了
1
,然后用
return
语句代替
echo
,一切正常

这是您的代码:
echo“window.parent.CKEDITOR.tools.callFunction(1,{$url},''”

这是我的代码:
return“window.parent.CKEDITOR.tools.callFunction('{$request->CKEditorFuncNum}','{$url}',''”

我在Laravel 5.8上


希望它能帮助其他人。

这是唯一包含
script
html标记的字符串。Javascript不知道应该将其附加到DOM中,除非您告诉它。@Chay22与此实现类似,在我的其他项目中可以正常工作。您应该看看,您还应该在“attachImage”方法中使用“return”语句,因为在“uploadImageContent”方法中,只将结果返回回调函数,而不返回客户端。
echo "<script>window.parent.CKEDITOR.tools.callFunction(1,'{$url}','')</script>";