【发布时间】:2017-05-08 14:54:40
【问题描述】:
在这里我使用“Codeigniter”,在我的方法中...... 为了上传图片,我使用了 Ajax 调用,我的 ajax 数据取自标签 'img' 的值 .attr ('src'), 数据值为base64码。
page_ajax_call.php
if ( isset($_POST['data_image_post']) ) {
$to_upload = 'users/VegetaSSJ/images/user_pp.png';
$to_convert = 'users/VegetaSSJ/images/'.time().'.jpg';
$img_base64 = $this->input->post('data_image_post');
list( $type, $data ) = explode(';', $img_base64);
list( , $data ) = explode(',', $img_base64);
$decode = base64_decode($data);
file_put_contents($to_upload, $decode);
$ori_img_base64 = imagecreatefrompng($to_upload);
imagejpeg($ori_img_base64, $to_convert, 100);
unlink($to_upload);
}
Ajax.js
$('.wrap-img-attachment img').each(function(){
$.ajax({
url : "home",
type : "post",
data : {'data_image_post': $(this).attr('src')},
success : function(data) {
console.log(data);
}
});
});
请更正我的代码中的错误
【问题讨论】:
标签: php jquery ajax codeigniter