公眾平台開發,表單要上傳圖片。思路見代碼
html部分
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部分
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到新的空白頁。
求解!