ไฟล์ upload.php ที่แปลงไฟล์รูปเป็น binary
โค้ด: เลือกทั้งหมด
$fileImg = 'uploads/before/'.$_FILES['upl']['name'];
$binaryPic = base64_encode_image ($fileImg,$_FILES['upl']['type']); //----ใช้ function แปลงรูปเป็น binary
header('Content-type: application/json');
echo '{"status":"success", "filename": "'.$_FILES['upl']['name'].'","fileimgsize":"640x640","filesize":"'.$show_file_img_before_size.'","fileblob":"'.$binaryPic.'"}';
exit;
}
โค้ด: เลือกทั้งหมด
var jqXHR = data.submit();
row=parseInt(row)+1;
jqXHR.done(function(result) {
tpl.find('.aft').text(result.filename).append('<i>Size '+result.fileimgsize+'<br><div style="color:#ff29e6;">'+result.filesize+'</div></i>');
//-----ส่วนที่จะกด download ออกมาเป็นไฟล์รูป
//----result.fileblob เป็นตัวที่ส่งมาเป็น binary
tpl.find('.download').append('<a href="exportimg.php?val='+result.fileblob+'">Download</a><br><i style="color:#000">40%</i>');
console.log(result.status);
});