jquery+php ajax上传多图片即时显示
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | <! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> < html xmlns="http://www.w3.org/1999/xhtml"> < head > < meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> < title >问卷列表</ title > < link href=" <!--{$csspath}--> /basc.css" rel="stylesheet" type="text/css"/> < link href=" <!--{$csspath}--> /styleG.css" rel="stylesheet" type="text/css"/> < script src=" <!--{$jspath}--> /jquery-1.7.2.js"></ script > <!-- artdialog插件 --> < script src=" <!--{$jspath}--> /artDialog4.1.6/jquery.artDialog.source.js?skin=blue"></ script > < script src=" <!--{$jspath}--> /artDialog4.1.6/plugins/iframeTools.source.js"></ script > < script src=" <!--{$jspath}--> /admin.js"></ script > <!--layer--> < link rel="stylesheet" href=" <!--{$jspath}--> /layer/skin/default/layer.css"> < script src=" <!--{$jspath}--> /layer/layer.js"></ script > </ head > < body > < style > table th{padding-left: 100px!important; width: 245px;} </ style > < div class="pubBox"> < form action="" method='post' id="batch-form"> < div class="pubtabBox"> < div class="TabBoxT"> < dl class="navTab"> < dt class="on">< a href="#" >用户信息</ a ></ dt > </ dl > </ div > < div class="TabBoxC"> < div > < div class="pubTabel"> < table class="tabelLR"> < tr > < th > 用户名:</ th > < td > < input type="text" name="username" value=" <!--{$info.username}--> " style="width: 300px;"> </ td > </ tr > < tr > < th > 新密码:</ th > < td > < input type="password" name="password" style="width: 300px;"> </ td > </ tr > < tr > < th > 重复密码:</ th > < td > < input type="password" name="password" style="width: 300px;"> </ td > </ tr > </ table > </ div > </ div > </ div > </ div > < div class="pubtabBox" style="margin-top: 10px;"> < div class="TabBoxT"> < dl class="navTab"> < dt class="on">< a href="#" >企业信息</ a ></ dt > </ dl > </ div > < div class="TabBoxC"> < div > < div class="pubTabel"> < table class="tabelLR"> < tr > < th > 注册号:</ th > < td > < input type="text" name="registration_number" value=" <!--{$info.registration_number}--> " style="width: 300px;"> </ td > </ tr > < tr > < th > 组织机构代码:</ th > < td > < input type="text" name="organization_code" value=" <!--{$info.organization_code}--> " style="width: 300px;"> </ td > </ tr > < tr > < th > 税务登记号:</ th > < td > < input type="text" name="tax_code" value=" <!--{$info.tax_code}--> " style="width: 300px;"> </ td > </ tr > < tr > < th > 营业执照(三证合一):</ th > < td > < img src="/static/uploadfile/1.jpg" alt="" width="200" class="license_up"> < p > < input class="files" id="license_up" name="license_up" type="file"/> < input type="text" name="license" class="license_up_val"> </ p > </ td > </ tr > </ table > </ div > </ div > </ div > </ div > < div class="pubtabBox" style="margin-top: 10px;"> < div class="TabBoxT"> < dl class="navTab"> < dt class="on">< a href="#" >法定代表人信息</ a ></ dt > </ dl > </ div > < div class="TabBoxC"> < div > < div class="pubTabel"> < table class="tabelLR"> < tr > < th > 法定代表人归属地:</ th > < td > < input type="text" name="person_address" value=" <!--{$info.person_address}--> " style="width: 300px;"> </ td > </ tr > < tr > < th > 法定代表人姓名:</ th > < td > < input type="text" name="person_name" value=" <!--{$info.person_name}--> " style="width: 300px;"> </ td > </ tr > < tr > < th > 法人身份证照片:</ th > < td > < img src="/static/uploadfile/1.jpg" alt="" width="200" class="card_1_up"> < p > < input class="files" id="card_1_up" name="card_1_up" type="file"/> < input type="text" name="card_1" class="card_1_up_val"> </ p > < p >身份证正面</ p >< br > < img src="/static/uploadfile/2.jpg" alt="" width="200" class="card_2_up"> < p > < input class="files" id="card_2_up" name="card_2_up" type="file"/> < input type="text" name="card_2" class="card_2_up_val"> </ p > < p >身份证反面</ p >< br > </ td > </ tr > </ table > </ div > </ div > </ div > </ div > < div class="pubtabBox" style="margin-top: 10px;"> < div class="TabBoxT"> < dl class="navTab"> < dt class="on">< a href="#" >申请人信息</ a ></ dt > </ dl > </ div > < div class="TabBoxC"> < div > < div class="pubTabel"> < table class="tabelLR"> < tr > < th > 姓名:</ th > < td > < input type="text" name="apply_name" value=" <!--{$info.apply_name}--> " style="width: 300px;"> </ td > </ tr > < tr > < th > 身份证号码:</ th > < td > < input type="text" name="apply_id" value=" <!--{$info.apply_id}--> " style="width: 300px;"> </ td > </ tr > < tr > < th > 手机号:</ th > < td > < input type="text" name="apply_phone" value=" <!--{$info.apply_phone}--> " style="width: 300px;"> </ td > </ tr > < tr > < th > 邮箱:</ th > < td > < input type="text" name="apply_email" value=" <!--{$info.apply_email}--> " style="width: 300px;"> </ td > </ tr > < tr > < th > 申请人身份证照片:</ th > < td > < img src="/static/uploadfile/1.jpg" alt="" width="200" class="apply_card_1_up"> < p > < input class="files" id="apply_card_1_up" name="apply_card_1_up" type="file"/> < input type="text" name="apply_card_1" class="apply_card_1_up_val"> </ p > < p >身份证正面</ p >< br > < img src="/static/uploadfile/2.jpg" alt="" width="200" class="apply_card_2_up"> < p > < input class="files" id="apply_card_2_up" name="apply_card_2_up" type="file"/> < input type="text" name="apply_card_2" class="apply_card_2_up_val"> </ p > < p >身份证反面</ p >< br > </ td > </ tr > </ table > </ div > < div class="pubTabelBot"> < input type="submit" hidefocus="hide" value="确定" class="btn1">< input type="button" hidefocus="hide" value="取消" class="btn2" onclick="javascript:history.back();"> </ div > < div class="pubTabelBot"> < div class="pageGo"> <!--{$pageStr}--> </ div > </ div > </ div > </ div > </ div > </ form > </ div > </ body > </ html > < script src="https://www.helloweba.com/demo/ajaxsubmit/jquery.form.min.js" type="text/javascript"></ script > <!--上传js--> < script src=" <!--{$jspath}--> /member_update.js"></ script > < script type="text/javascript"> </ script > |
member_update.js 文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | $( function () { to1( 'license_up' , 'up1' ); to1( 'card_1_up' , 'up2' ); to1( 'card_2_up' , 'up3' ); to1( 'apply_card_1_up' , 'up4' ); to1( 'apply_card_2_up' , 'up5' ); }); function to1(id, up) { $( '#' +id).wrap( "<form id=" +up+ " action='/admin/question/grade/member_update' method='post' enctype='multipart/form-data'></form>" ); $( '#' +id).change( function (){ $( '#' +up).ajaxSubmit({ dataType: 'json' , beforeSend: function () { layer.load(2); }, success: function (data) { if (data.status == 0) { $( '.' +id).attr( 'src' , data.path); $( '.' +id+ '_val' ).attr( 'value' , data.path); alert( 'succees' ); layer.closeAll(); } else { alert(data.data); layer.closeAll(); } return false ; } }); }); } |
php访问方法:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | public function member_updateAction() { if (isPost() && $_FILES ){ $file = $_FILES [ 'file' ][ 'tmp_name' ]; $name = array_keys ( $_FILES ); // 自动获取上传的name Load::load_class( 'fileupload' ,DIR_BF_ROOT. 'classes' ,0); $up = new fileupload; $up -> set( "path" , DIR_ROOT . '../static/uploadfile/grade' ); $up -> set( "maxsize" , 200000000); $up -> set( "allowtype" , array ( "gif" , "png" , "jpg" , "jpeg" )); if ( $up -> upload( $name [0])) { // 获取上传后的文件名称 $file_path = '/static/uploadfile/grade/' . $up ->getFileName(); echo json_encode( array ( 'status' => 0, 'name' => $name [0], 'path' => $file_path )); exit (); } else { echo json_encode( array ( 'statsu' => 1, 'data' => $up ->getErrorMsg())); exit (); } } $this ->display( 'question/grade/member_update' ); } |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步