我正在使用CKEditor4。已使用image2插件成功上传了该图像,并且该图像显示在CKEditor 内部,但是当我尝试显示在laravel刀片文件中时,该图像没有显示。它给出了一个错误,并且在数据库中,图像路径未替换为本地文件夹路径。
在刀片文件中
<div class="modal_text">
{!!html_entity_decode(stripslashes($final_theme['home_modal']['home_modal_description']))!!}
</div>
这是表格,我为CKEditor添加了js
<script type="text/javascript">
$(function () {
//for multiple languages
@foreach($result['languages'] as $languages)
// Replace the <textarea id="editor1"> with a CKEditor
// instance, using default configuration.
CKEDITOR.replace( 'editor{{$languages->languages_id}}', {
extraPlugins: 'image2,lineheight,uploadimage,filebrowser,blockpasteimagelink,font,richcombo',
// note: basically, local image is handled by uploadimage, while web image is handled by blockpasteimagelink
uploadUrl: '{!! route('ckeditor.imageUpload',['_token' => csrf_token()]) !!}',
});
@endforeach
//bootstrap WYSIHTML5 - text editor
$(".textarea").wysihtml5();
});
</script>
控制器中的imageUpload方法
public function ckeupload()
{
$upload_dir = array(
'img' => public_path().'/uploads/questions/',
);
$imgset = array(
// 'maxsize' => 2000,
// 'maxwidth' => 900,
// 'maxheight' => 800,
'minwidth' => 10,
'minheight' => 10,
'type' => array('bmp', 'gif', 'jpg', 'jpeg', 'png'),
);
// If 0, will OVERWRITE the existing file
define('RENAME_F', 1);
// init
$re = array(
'uploaded' => false,
// 'post' => $P,
// 'fileName' => 'test.jpg',
// 'url' => 'path/to/file.jpg',
// 'error' => array('message' => '' ),
);
if (isset($_FILES['upload']) && strlen($_FILES['upload']['name']) > 1) {
define('F_NAME', preg_replace('/\.(.+?)$/i', '', basename($_FILES['upload']['name']))); //get filename without extension
// get protocol and host name to send the absolute image path to CKEditor
$site = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] . '/';
$sepext = explode('.', strtolower($_FILES['upload']['name']));
$type = end($sepext); // gets extension
$upload_dir = in_array($type, $imgset['type']) ? $upload_dir['img'] : $upload_dir['audio'];
//$upload_dir = trim($upload_dir, '/') . '/';
//checkings for image or audio
if (in_array($type, $imgset['type'])) {
// list($width, $height) = getimagesize($_FILES['upload']['tmp_name']); // image width and height
if (isset($width) && isset($height)) {
if ($width > $imgset['maxwidth'] || $height > $imgset['maxheight']) $re .= '\\n Width x Height = ' . $width . ' x ' . $height . ' \\n The maximum Width x Height must be: ' . $imgset['maxwidth'] . ' x ' . $imgset['maxheight'];
if ($width < $imgset['minwidth'] || $height < $imgset['minheight']) $re .= '\\n Width x Height = ' . $width . ' x ' . $height . '\\n The minimum Width x Height must be: ' . $imgset['minwidth'] . ' x ' . $imgset['minheight'];
if ($_FILES['upload']['size'] > $imgset['maxsize'] * 1000) $re .= '\\n Maximum file size must be: ' . $imgset['maxsize'] . ' KB.';
}
} else $re .= 'The file: ' . $_FILES['upload']['name'] . ' has not the allowed extension type.';
//set filename; if file exists, and RENAME_F is 1, set "img_name_I"
// $p = dir-path, $fn=filename to check, $ex=extension $i=index to rename
function setFName($p, $fn, $ex, $i)
{
if (RENAME_F == 1 && file_exists($p . $fn . $ex)) return setFName($p, F_NAME . '_' . ($i + 1), $ex, ($i + 1));
else return $fn . $ex;
}
$f_name = setFName($upload_dir, F_NAME, ".$type", 0);
$uploadpath = $upload_dir . $f_name; // full file path
// If no errors, upload the image, else, output the errors
if (true) {
// print_r($_FILES);exit;
if (move_uploaded_file($_FILES['upload']['tmp_name'], $uploadpath)) {
//$CKEditorFuncNum = getUrlParam['CKEditorFuncNum'];
$url = url('/').'/uploads/questions/' . $f_name;
$msg = F_NAME . '.' . $type . ' successfully uploaded: \\n- Size: ' . number_format($_FILES['upload']['size'] / 1024, 2, '.', '') . ' KB';
//$re = in_array($type, $imgset['type']) ? "window.parent.CKEDITOR.tools.callFunction($CKEditorFuncNum, '$url', '$msg')" //for img
// : 'var cke_ob = window.parent.CKEDITOR; for(var ckid in cke_ob.instances) { if(cke_ob.instances[ckid].focusManager.hasFocus) break;} cke_ob.instances[ckid].insertHtml(\'<audio src="'. $url .'" controls></audio>\', \'unfiltered_html\'); alert("'. $msg .'"); var dialog = cke_ob.dialog.getCurrent(); dialog.hide();';
$re['uploaded'] = true;
$re['url'] = $url;
$re['fileName'] = $f_name;
@header('Content-type: text/html; charset=utf-8');
$re = json_encode($re);
echo $re;
//print_r($re);
} else $re = 'alert("Unable to upload the file")';
} else $re = 'alert("' . $re . '")';
}
//@header('Content-type: text/html; charset=utf-8');
//echo '<script>'. $re .';</script>';
}
但是当我试图存储在数据库中时,我会得到这样的图像路径
这是错误的。因此,如何添加或设置本地路径
url: "http://localhost/Haircastle/git/HairCastle/public/images/media/ckeditor/15256_10.jpg"
在CKEditor的图片标签中?
如果有人知道,请帮助。