微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

上传多张图片 multiple使用

<div class="cnblogs_code">

PHP" 
         
    

当前页面选择浏览:

选择文件:

选中的上传图片信息:

后台处理:

= D('bidnotice' = ['img' = (['name' </span><span style="color: #0000ff"&gt;for</span> (<span style="color: #800080"&gt;$i</span> = 0; <span style="color: #800080"&gt;$i</span> < <span style="color: #800080"&gt;$count</span>; <span style="color: #800080"&gt;$i</span>++<span style="color: #000000"&gt;) { </span><span style="color: #0000ff"&gt;if</span> (<span style="color: #800080"&gt;$file</span>['size'][<span style="color: #800080"&gt;$i</span>] > 3145728<span style="color: #000000"&gt;) { </span><span style="color: #800080"&gt;$this</span>->error("<a href="https://www.jb51.cc/tag/shangchuan/" target="_blank" class="keywords">上传</a><a href="https://www.jb51.cc/tag/wenjian/" target="_blank" class="keywords">文件</a>超过限定大小");<span style="color: #0000ff"&gt;exit</span><span style="color: #000000"&gt;; } </span><span style="color: #800080"&gt;$name</span> = <span style="color: #008080"&gt;strrchr</span>(<span style="color: #800080"&gt;$file</span>['name'][<span style="color: #800080"&gt;$i</span>],'.'<span style="color: #000000"&gt;); </span><span style="color: #800080"&gt;$str</span> = <span style="color: #008080"&gt;rand</span>(111,999<span style="color: #000000"&gt;); </span><span style="color: #800080"&gt;$tmpName</span> = <span style="color: #008080"&gt;date</span>('Y-m-d') . <span style="color: #800080"&gt;$str</span><span style="color: #000000"&gt;; </span><span style="color: #800080"&gt;$newName</span> = <span style="color: #800080"&gt;$tmpName</span> . <span style="color: #800080"&gt;$name</span><span style="color: #000000"&gt;; </span><span style="color: #800080"&gt;$upload_path</span> = "../Public/Images/zhongbiao/"<span style="color: #000000"&gt;; </span><span style="color: #800080"&gt;$typeArr</span> = <span style="color: #0000ff"&gt;array</span>('.jpg','.jpeg','.png'<span style="color: #000000"&gt;); </span><span style="color: #0000ff"&gt;if</span> (<span style="color: #800080"&gt;$file</span>['error'][<span style="color: #800080"&gt;$i</span>] == 0<span style="color: #000000"&gt;) { </span><span style="color: #0000ff"&gt;if</span> (<span style="color: #008080"&gt;in_array</span>(<span style="color: #800080"&gt;$name</span>,<span style="color: #800080"&gt;$typeArr</span><span style="color: #000000"&gt;)) { </span><span style="color: #0000ff"&gt;if</span> (<span style="color: #008080"&gt;is_uploaded_file</span>(<span style="color: #800080"&gt;$file</span>['tmp_name'][<span style="color: #800080"&gt;$i</span><span style="color: #000000"&gt;])) { </span><span style="color: #0000ff"&gt;if</span> (<span style="color: #008080"&gt;move_uploaded_file</span>(<span style="color: #800080"&gt;$file</span>['tmp_name'][<span style="color: #800080"&gt;$i</span>],<span style="color: #800080"&gt;$upload_path</span> . <span style="color: #800080"&gt;$newName</span><span style="color: #000000"&gt;)) { </span><span style="color: #800080"&gt;$fujian</span> = "fujian".<span style="color: #800080"&gt;$i</span>; <span style="color: #008000"&gt;//</span><span style="color: #008000"&gt; 拼接 每张<a href="https://www.jb51.cc/tag/tupian/" target="_blank" class="keywords">图片</a>存入对应的字段.<a href="https://www.jb51.cc/tag/shujuku/" target="_blank" class="keywords">数据库</a> 设计 字段 dujian0,dujian1,dujian2...</span> <span style="color: #800080"&gt;$data</span>[<span style="color: #800080"&gt;$fujian</span>] = <span style="color: #800080"&gt;$newName</span><span style="color: #000000"&gt;; } } } } }

<span style="color: #000000">     <span style="color: #800080">$data['lsnumber'] = <span style="color: #800080">$_POST['<span style="color: #000000"><span style="color: #000000"><span style="color: #800080">lsnumber'<span style="color: #000000">];
<span style="color: #800080">$data<span style="color: #800080">['city'] = $_POST['city'<span style="color: #000000"><span style="color: #800080">];<span style="color: #800080">
...

<span style="color: #800080">$model->add(<span style="color: #800080">$data<span style="color: #000000">);
<span style="color: #800080">$this->success("添加成功",<span class="hljs-string">'Goods/list'<span style="color: #000000">);
<span style="color: #000000">
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐