无为清净楼资源网 Design By www.qnjia.com
本文实例讲述了TP5框架实现上传多张图片的方法。分享给大家供大家参考,具体如下:
1、效果图(每点击一次‘添加选项',就会有一个新的 file 框来添加新的图片)
2、view
<!--不要忘了引入jquery文件--> <!-- post传值方式和文件传输协议一定要加上 --> <input type="file" name="image[]"> <input type="button" id="add" name="add" value="+ 添加选项"> <button type="submit" name="submit">添加</button> <script type="text/javascript"> $("#add").click(function(){ $(this).before('<input type="file" name="image[]">'); }); </script>
3、controller
//接收从view来的图片数组 $image=request()->file('image'); //实例化模型,并调用里面的添加图片的方法 $details = new Details(); $info = $details->add($image); if($info === 1) { return '操作成功'; } else { return '操作失败'; }
4、model
//将接收到的 $image foreach遍历添加 foreach($image as $image) { //实例化模型 $details = new Details(); $time=date('Ymd',time()); //将当前的时间戳定义为文件名 $filename=time(); //检测是否存在存放图片的文件夹 if(!file_exists(ROOT_PATH . 'public' . DS .'static'. DS .'img')) { //创建文件 mkdir(ROOT_PATH . 'public' . DS .'static'. DS .'img'); } //上传图片 $info=$image->move(ROOT_PATH . 'public' . DS .'static'. DS .'img'.DS.$time,$filename); //将图片路径存放在数据库中 $details->url = $time.DS.$info->getFileName(); $details->allowField(true)->save(); } return 1;
5、over over over
更多关于thinkPHP相关内容感兴趣的读者可查看本站专题:《ThinkPHP入门教程》、《thinkPHP模板操作技巧总结》、《ThinkPHP常用方法总结》、《codeigniter入门教程》、《CI(CodeIgniter)框架进阶教程》、《Zend FrameWork框架入门教程》及《PHP模板技术总结》。
希望本文所述对大家基于ThinkPHP框架的PHP程序设计有所帮助。
标签:
TP5,上传多张图片
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
更新日志
2024年09月25日
2024年09月25日
- 《叶倩文 真心真意过一生》[WAV+CUE][400MB]
- 潘越云.1985-世间女子(滚石25周年经典复刻版)【滚石】【WAV+CUE】
- 陈柏宇.2009-CANT.BE.HALF【SONY】【WAV+CUE】
- 李明依.1989-小女生【滚石】【WAV+CUE】
- 《李荣浩 新时代创作新人王》[WAV分轨][310MB]
- 《黑鸭子与马头琴 史上最动听草原音乐》[WAV+CUE][320MB]
- 《汽车发烧音乐精选CD18》[FLAC+CUE][7.1G]
- 郑希怡.2004-Perfect.Date【英皇娱乐】【FLAC分轨】
- 群星.1994-宝丽金超级孖宝2CD【宝丽金】【WAV+CUE】
- 林忆莲.2019-0(2023精装版)【环球】【WAV+CUE】
- Supper.Moment.2016-The.Moment【寰亚】【FLAC分轨】
- 范莉丝.1979-送郎一朵牵牛花(LP版)【大联机构】【WAV+CUE】
- 刘宇.2024-宇宙诗人【哔哟哔哟文化】【FLAC分轨】
- 《全景声白噪音》沉浸式大自然助眠 带你听自然的声音[mp3]
- 纯音入心系列纯音乐《古筝精选 十指弹一赏心曲一心奏出世人心》1CD[MP3][582MB]