微信公众平台开发,表单要上传图片。思路见代码
html部分
<form id='form_file' method="post" action="upload.php" target='frameFile'enctype="multipart/form-data" >
@@##@@
<input type="file" name='image_url' id='file_upload' value="上传图片"/>
<input type="hidden" name='img' value=''>
</form>js部分
$(function(){
$('#file_upload').change(function(){
$('#form_file').submit();
});
});
function upload_success (msg) {
if (msg.err == 0) {
$('#pre-img').attr('src', msg.file_path);
$('input[name="img"]').val(msg.file_path);
} else {
swal(msg.msg);
return false;
}
}PHP处理
// 图片上传错误处理
if ($img_info['error']) {
$response = array('err'=>1, 'msg'=>$img_info['error']);
} else {
$response = array(
'err'=>0,
'file_path'=>$img_info['image_url']['savepath'].$img_info['image_url']['savename']
);
}
电脑上测试是正常,但是传到微信上就会post到新的空白页。
求解!
微信公众平台开发,表单要上传图片。思路见代码
html部分
<form id='form_file' method="post" action="upload.php" target='frameFile'enctype="multipart/form-data" >
@@##@@
<input type="file" name='image_url' id='file_upload' value="上传图片"/>
<input type="hidden" name='img' value=''>
</form>js部分
$(function(){
$('#file_upload').change(function(){
$('#form_file').submit();
});
});
function upload_success (msg) {
if (msg.err == 0) {
$('#pre-img').attr('src', msg.file_path);
$('input[name="img"]').val(msg.file_path);
} else {
swal(msg.msg);
return false;
}
}PHP处理
// 图片上传错误处理
if ($img_info['error']) {
$response = array('err'=>1, 'msg'=>$img_info['error']);
} else {
$response = array(
'err'=>0,
'file_path'=>$img_info['image_url']['savepath'].$img_info['image_url']['savename']
);
}
电脑上测试是正常,但是传到微信上就会post到新的空白页。
求解!
微信是一款手机通信软件,支持通过手机网络发送语音短信、视频、图片和文字。微信可以单聊及群聊,还能根据地理位置找到附近的人,带给大家全新的移动沟通体验,有需要的小伙伴快来保存下载体验吧!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号