HTML 텍스트를 처리하는 데 ckeditor를 사용하고 있습니다. 이미지를 붙여 넣으면 ckeditor가 이미지 업로드를 수행합니다. 나는 pdf 라이브러리 인 TCPDF와 MPDF를 사용했다. 두 개의 별개의 오류가있다. 하나는 각 라이브러리에있다.업로드 된 이미지가 PDF 라이브러리에 오류를 발생합니다.
<?php
session_start();
class image{
private $save_path = 'uploads/';
private $image_string = '';
private $image_name = '';
private $image;
private $response = array();
public $loaded = false;
public function __construct(){
$this->response = array(
'error' => 1,
'message' => 'unknown error.'
);
$this->image_string = filter_input(INPUT_POST, 'image');
$ext = substr($this->image_string,11,3);
$randomLetters = $rand = substr(md5(microtime()),rand(0,26),6);
$imgnumber = count(scandir($this->save_path));
$this->image_name = "$imgnumber$randomLetters.$ext";
if(!empty($this->image_name) && !empty($this->image_string)){
$this->loaded = true;
}
}
public function save(){
if(!empty($this->image_name) && !empty($this->image_string)){
return $this->progress();
}
else{
$this->response['message'] = 'Error. Not all required infor is given.';
$this->response['error'] = 1;
return $this->response;
}
}
private function progress(){
$imgarr = explode(',', $this->image_string);
if(!isset($imgarr[1])){
$this->response['message'] = 'Error on post data image. String is not the expected string.';
$this->response['error'] = 1;
return $this->response;
}
$this->image = base64_decode($imgarr[1]);
if(!is_null($this->image)){
$file = $this->save_path . $this->image_name;
if(file_exists($file)){
$this->response['message'] = 'Image already exists on server.';
$this->response['error'] = 1;
return $this->response;
}
if(file_put_contents($file, $this->image) !== false){
$this->response['message'] = 'Image saved to server';
$this->response['error'] = 0;
$this->response['source'] = '../plugins/imageuploader/'.$file;
return $this->response;
}
else{
$this->response['error'] = 1;
$this->response['message'] = 'Error writing file to disk';
return $this->response;
}
}
else{
$this->response['message'] = 'Error decoding base64 string.';
return $this->response;
}
}
}
$img = new image();
if($img->loaded){
$result = $img->save();
echo json_encode($result);
}
else{
$result = array(
'error' => 1,
'message' => 'Not all post data given'
);
echo json_encode($result);
}
?>
이게 무슨 오류가 발생할 수 있습니다 : 다음과 같이 업로드 이미지
mPDF error: IMAGE Error (SOURCE-IMAGE): Error parsing temporary file image object created with GD library to parse PNG image
TCPDF ERROR: [Image] Unable to get the size of the image: (SOURCE-IMAGE)
내 코드 ckeditor에서 붙여 넣기 때?
편집 : 아약스 코드는 ckeditor 코드의 일부, 일부는 여기에있는 이미지는 base64로 코드처럼 온다 : 당신은 몇 가지 문자를 인코딩하는 데 필요한 데이터를 전송하기 전에
function h(a, d) {
if (a && "function" === typeof a.getAsFile) {
var b = a.getAsFile(), c = new FileReader;
c.onload = function (a) {
var fd = new FormData();
fd.append('image', a.target.result); //the base64 of image with format equals in src of tag img in html
$.ajax({
type: 'POST',
url: '../plugins/imageuploader/ajaxupload.php',
data: fd,
processData: false,
contentType: false,
dataType: 'json'
}).done(function(data) {
if((data.error == 0) && (typeof data.source != 'undefined')){
//alert(data.source);
var b = d.document.createElement("img", {attributes: {src: data.source}});
setTimeout(function() {
d.insertElement(b)
}, 10)
}else{
alert('Não foi possível carregar a imagem:\nErro - '+data.message); // show the message error if it can't be uploaded.
}
});
};
c.readAsDataURL(b);
}
}
이미지 파일이 저장된 디렉토리에 대한 사용 권한을 확인 (쓰기) 했습니까? – Johan
이미지가 업로드됩니다, 내가 좋아, 이미지를 업로드 할 수있는 방법은 : 이미지를 붙여 넣을 때, 나는 base64 인코딩 이미지를 얻은 다음 base64 디코딩 된 문자열 @ 조한 –
안녕하세요, 이미지의 base64 인코딩 된 문자열을 표시 할 수 있습니까? – mandar