当我尝试使用CKEditor
在PHP
中上传图片时,它成功上传了,但是当我按下OK按钮时,它给了我错误upload image source URL is missing
,有人可以检查我的代码吗并帮助我如何解决此问题?在这里,我已经放置了整个代码
if($_FILES['upload']['name']) {
if($_FILES['upload']['error'] == 0) {
$new_file_name = strtolower($_FILES['upload']['tmp_name']);
if($_FILES['upload']['size']>300000) {
echo json_encode(array('status'=>0,'msg'=>"Your file size is to large."));
} else {
require_once($_SERVER['DOCUMENT_ROOT'].'/wp-admin/includes/image.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/wp-admin/includes/file.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/wp-admin/includes/media.php');
$file_id = media_handle_upload( 'upload', 0 );
if(is_wp_error($file_id)) {
echo json_encode(array('status'=>0,'msg'=>"Error uploading file"));
} else {
$image_data = wp_get_attachment_image_src($file_id);
$image_url = $image_data[0];
//echo json_encode(array('status'=>1,'msg'=>"",'id'=>$file_id,'url'=>$image_url));
echo '<script>window.parent.CKEDITOR.tools.callFunction(" + CKEditorFuncNum + ", \"" + url + "\");</script>';
}
}
} else {
echo json_encode(array('status'=>0,'msg'=>$_FILES['upload']['error']));
}
}