帝王谷资源网 Design By www.wdxyy.com
本文所述为一个实用的PHP多图片文件上传类,其支持gif、jpg、jpeg、pjpeg、png格式的多图片上传功能,类中还可限制图片类型、上传图片的大小、设置上传目录、一些提交判断等功能。此外该类并不局限于图片的上传,也可以上传TXT/RAR等文件类型,只是需要对代码进行一下修改,感兴趣的读者可以自己尝试一下。
php多图片上传类完整功能代码如下:
<"this->file_name " . '文件上传失败!<br/>'; break; } self :: __destruct(); }else{ smfiletypeflag = array_search(smfiletype, this -> file_type_array); // 进行真实格式验证 if(smfiletypeflag != false){ file = fopen(this -> file_tmp_name, "rb"); bin = fread(file, 10); fclose(file); strInfo = @unpack("c10chars", bin); typeCode = intval(strInfo['chars1'] . strInfo['chars2']); smfiletypeflag = array_search(typeCode, this -> file_type_real_array); if(smfiletypeflag == false){ // 判断是否是png图片 typeCode = intval(strInfo['chars2'] . strInfo['chars3'] . strInfo['chars4']); smfiletypeflag = array_search(typeCode, this -> file_type_real_array); if(smfiletypeflag == false){ // 判断是否是jpg图片 $typeCode = intval(strInfo['chars7'] . strInfo['chars8'] . strInfo['chars9'] . strInfo['chars10']); smfiletypeflag = array_search(typeCode, this -> file_type_real_array); } } } if($smfiletypeflag == false){ $smfilemessage = '<strong>文件类型不对,请核实!</strong>'; self :: __destruct(); }else{ $resflag = $this -> move_file($this -> file_tmp_name, this -> file_name); if (resflag == 1){ $smfilemessage = '文件上传成功!'; self :: totalsize += intval($smfilesize); self :: __destruct(); }else{ $smfilemessage = '<strong>文件上传失败!</strong>'; self :: __destruct(); } } } $smfilesizeformat = $this -> size_BKM(smfilesize); echo '<tr> <td align="left" >' . smfilename . '</td> <td align="center" >' . smfiletype . '</td> <td align="center" >' . smfilesizeformat . '</td> <td align="center" >' . smfilemessage . '</td> </tr>'; } function move_file(mvfiletmp, mvfilename){ // 移动文件 mvfilenamearr = explode('.', basename(mvfilename)); mvfilenamearr[0] = this -> rand_string(); mvfilename = implode('.', mvfilenamearr); if (is_uploaded_file(mvfiletmp)){ uploadfile = self :: FILE_PATH . "mvfilename"; result = move_uploaded_file(mvfiletmp, uploadfile); return result; } } function rand_string(){ string = md5(uniqid(rand() . microtime())); return string; } function size_BKM(size){ // B/KB/MB单位转换 if(size < 1024) { size_BKM = (string)size . " B"; } elseif(size < (1024 * 1024)) { size_BKM = number_format((double)(size / 1024), 1) . " KB"; }else { size_BKM = number_format((double)(size / (1024 * 1024)), 1) . " MB"; } return size_BKM; } } ?>
读者可以将上述代码复制到PHP文件中,并保存文件名为:more_upload_file.class.php,在使用时include该文件即可。
标签:
PHP,多图片,上传
帝王谷资源网 Design By www.wdxyy.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
帝王谷资源网 Design By www.wdxyy.com
暂无评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
2024年10月26日
2024年10月26日
- 群星2013-青春缤纷辑压箱宝大公开3CD2[新加坡限量版][WAV整轨]
- 林育群.2013-BalladShow(日本版)【环球】【WAV+CUE】
- 陈加洛.1992-痛到感觉不到【宝丽金】【WAV+CUE】
- 群星.2023-宿命之敌电视剧原声带【韶愔音乐】【FLAC分轨】
- 東京事変-大発見[FLAC+CUE]
- 椎名林檎-三文ゴシップ[FLAC+CUE]
- 2024年08月04日
- 裘德《裘德「最后的水族馆」演唱会LIVE》[320K/MP3][228.89MB]
- 裘德《裘德「最后的水族馆」演唱会LIVE》[24bit 48kHz][FLAC/分轨][2.08G]
- 基因三重奏《如果你什么都不说 音乐会现场录音》[320K/MP3][145.37MB]
- 孟庭苇.1996-月亮说话(2020环球24KGOLD限量版)【上华】【WAV+CUE】
- 群星.1997-新艺宝优质音响系列·国语精选监听版【新艺宝】【WAV+CUE】
- 阿桑.2005-寂寞在唱歌(星外星引进版)【华研国际】【WAV+CUE】
- 基因三重奏《如果你什么都不说 音乐会现场录音》[FLAC/分轨][287.43MB]
- 蔡题谦《我爱你,却依然要看你走》[320K/MP3][88.65MB]