File upload 如何在ckeditor 5中接收上载的图像文件?
我已经创建了一个上传脚本来接收使用CKEDITOR5简单上传适配器构建发送给它的文件。我已经用一个标准的上传文件类型对它进行了测试,使用了我修改过的文件类型字段中的$\u POST,它生成了正确的json响应供编辑器接收 然而,我不确定如何从编辑器本身检测输入,因为它不是来自输入字段File upload 如何在ckeditor 5中接收上载的图像文件?,file-upload,ckeditor5,File Upload,Ckeditor5,我已经创建了一个上传脚本来接收使用CKEDITOR5简单上传适配器构建发送给它的文件。我已经用一个标准的上传文件类型对它进行了测试,使用了我修改过的文件类型字段中的$\u POST,它生成了正确的json响应供编辑器接收 然而,我不确定如何从编辑器本身检测输入,因为它不是来自输入字段 <?php header('Content-Type: application/json; charset=utf-8'); header("Access-Control-Allow-Origin
<?php
header('Content-Type: application/json; charset=utf-8');
header("Access-Control-Allow-Origin: *");
header("Access-Control-Methods: PUT,GET,POST");
$uploadOk = 1;
$err = 0;
//getting the file
$mentionFilename = basename($_FILES["fileToUpload"]["name"]);
if ($mentionFilename == ""){
$err = 1;
}else{
//setting the uploaddir
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
//echo "File is an image - " . $check["mime"] . ".<BR>";
$uploadOk = 1;
} else {
//echo "File is not an image.<BR>";
$err = 2;
$uploadOk = 0;
}
}
// Check if file already exists
if (file_exists($target_file)) {
$err = 3;
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 5000000) {
//echo "Sorry, your file is too large.<BR>";
$err = 4;
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" && $imageFileType != "pdf" ) {
//echo "Sorry, only JPG, JPEG, PNG, GIF & PDF files are allowed.<BR>";
$err = 5;
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk > 0) {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
//echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.<BR>";
} else {
//echo "Sorry, there was an error uploading your file.<BR>";
$err = 6;
$uploadOk = 0;
}
}
}
switch ($err){
case "1":
//no fileneame in submissions
$errMsg = "There appeared to be no filename in the submission";
break;
case "2":
//the file is not an image
$errMsg = "The file submitted was not a permitted image type.";
case "3":
//file exists
$errMsg = "The file already exists.";
break;
case "4":
//file is too large
$errMsg = "The filesize of the upload is too large.";
case "5":
//Wrong filetype
$errMsg = "The file had the wrong filetype";
case "6":
//Problem uploading file
$errMsg = "There was a problem uploading the file.";
default:
//file was uplaoded succesfully
break;
}
if ($uploadOk > 0){
//return success message
$returnArr = array(
"url" => $target_file
);
}else{
//return error message
$returnArr = array(
"error" => array(
"message" => $errMsg
)
);
}
//sending back the response
echo json_encode($returnArr);
?>