मैं HTML पाठ करने के लिए ckeditor का उपयोग कर रहा हूं। जब मैं इसमें एक छवि पेस्ट करता हूं, तो ckeditor छवि अपलोड करता है। मैंने पीडीएफ लाइब्रेरी की तरह टीसीपीडीएफ और एमपीडीएफ की तरह उपयोग किया है, मुझे दो अलग-अलग त्रुटियां मिलीं, प्रत्येक लाइब्रेरी में से एक।छवि अपलोड की गई पीडीएफ लाइब्रेरी में त्रुटि का कारण बनता है
<?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 में पेस्ट है?
संपादित करें: ajax कोड, 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
छवि अपलोड की गई है, मैंने लिखने की अनुमतियों को सत्य की तरह सेट किया है, यह ठीक है, छवियों को अपलोड करने का तरीका यह है: जब पेस्ट छवि, मुझे छवि का बेस 64 एन्कोड मिलता है, तो मैं बेस 64 डीकोडेड स्ट्रिंग @Johan फ़ाइल में लिखता हूं –
हाय, क्या आप छवि की बेस 64 एन्कोडेड स्ट्रिंग दिखा सकते हैं? – mandar