[英]Cannot upload file, CKEditor 5 uploading image using PHP (CodeIgniter 3)
我正在嘗試通過 CKEditor 5 上傳圖像,圖像上傳正常,但 CKEditor 顯示此錯誤:“無法上傳文件”並從編輯器中刪除圖像無法上傳文件
這是我的 controller:
public function uploadCkeditor()
{
$config['upload_path'] = './assets/admin/img/uploads';
$config['allowed_types'] = 'gif|jpg|png|jpg';
$config['max_size'] = 2000;
$new_name = 'blog-'.date("Y-m-d").'-'.time();
$config['file_name'] = $new_name;
$this->load->library('upload', $config);
if(!$this->upload->do_upload('upload')){
echo json_encode(array('error'=> $this->upload->display_errors()));
} else {
$uploadData = $this->upload->data();
echo json_encode(array('file_name'=> $uploadData['file_name']));
}
}
這是 CKEditor 腳本:
<script src="<?= base_url();?>assets/admin/js/ckeditor.js"></script>
<script>
var myEditor;
ClassicEditor.create(document.getElementById('detail'),
{
ckfinder: {
uploadUrl: 'uploadCkeditor'
}}).then( editor => {
console.log( 'Editor was initialized', editor );
myEditor = editor;} ).catch( err => {
console.log( err );} );</script>
我遇到了同樣的問題,並通過在上傳處理 function 結束時返回以下 json 響應來修復它:
return new JsonResponse([
'uploaded' => true,
'fileName' => $image,
'url' => $url
], 200);
如果需要,您似乎還可以包含error
,帶有number
和message
鍵。
請注意,我在 Symfony 項目而不是 Codeigniter 項目中遇到了這個問題,但它應該以相同的方式工作。 我的答案是基於這個答案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.