欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

jquery php多资料上传

程序员文章站 2022-05-31 09:50:03
...
jquery php多文件上传

多文件上传

jquery php多资料上传
演示

?

index.php

PHP Code
  1. "uploaderform">??
  2. "upload.php"
    ?method="post"?enctype="multipart/form-data"?name="UploadForm"?id="UploadForm">??
  3. ????

    jquery?php多文件上传(本例限制为3个文件)

    ???
  4. ????
  5. ????class="small">"#"?id="AddMoreFileBox">添加上传框??
  6. ??????
  7. ????
    "AddFileInputBox">"fileInputBox"?style="margin-bottom:?5px;"?type="file"??name="file[]"/>
    ??
  8. ????
    class="sep_s">
    ??
  9. ??????
  10. ????
  11. ?????
  12. ??????
  13. ????
    "username"?type="text"?id="username"?value="freejs.net"?/>
    ??
  14. ??????
  15. ?????
  16. ?????class="button"?id="SubmitButton">Upload??
  17. ??????
  18. ????
    "progressbox">
    "progressbar">
    ?>
    "statustxt">0%
    ?>
    ??
  19. ??
??
  • "uploadResults">??
  • ????
    "center"?style="margin:20px;">"#"?id="ShowForm">打开/隐藏?表单
    ??
  • ????
    "output">
    ??
  • ??

    js文件

    JavaScript Code
    1. >???
    2. $(document).ready(function()?{???
    3. //elements??
    4. var?progressbox?????????=?$('#progressbox');?//progress?bar?wrapper??
    5. var?progressbar?????????=?$('#progressbar');?//progress?bar?element??
    6. var?statustxt???????????=?$('#statustxt');?//status?text?element??
    7. var?submitbutton????????=?$("#SubmitButton");?//submit?button??
    8. var?myform??????????????=?$("#UploadForm");?//upload?form??
    9. var?output??????????????=?$("#output");?//ajax?result?output?element??
    10. var?completed???????????=?'0%';?//initial?progressbar?value??
    11. var?FileInputsHolder????=?$('#AddFileInputBox');?//Element?where?additional?file?inputs?are?appended??
    12. var?MaxFileInputs???????=?3;?//Maximum?number?of?file?input?boxs??
    13. ??
    14. //?adding?and?removing?file?input?box??
    15. var?i?=?$("#AddFileInputBox?div").size()?+?1;??
    16. $("#AddMoreFileBox").click(function?()?{??
    17. ????????event.returnValue?=?false;??
    18. ????????if(i?
    19. ????????{??
    20. ????????????$('jquery php多资料上传').appendTo(FileInputsHolder);??
    21. ????????????i++;??
    22. ????????}??
    23. ????????return?false;??
    24. });??
    25. ??
    26. $("body").on("click",".removeclass",?function(e){??
    27. ????????event.returnValue?=?false;??
    28. ????????if(?i?>?1?)?{??
    29. ????????????????$(this).parents('span').remove();i--;??
    30. ????????}??
    31. ??????????
    32. });???
    33. ??
    34. $("#ShowForm").click(function?()?{??
    35. ??$("#uploaderform").slideToggle();?//Slide?Toggle?upload?form?on?click??
    36. });??
    37. ??????
    38. $(myform).ajaxForm({??
    39. ????beforeSend:?function()?{?//brfore?sending?form??
    40. ????????submitbutton.attr('disabled',?'');?//?disable?upload?button??
    41. ????????statustxt.empty();??
    42. ????????progressbox.show();?//show?progressbar??
    43. ????????progressbar.width(completed);?//initial?value?0%?of?progressbar??
    44. ????????statustxt.html(completed);?//set?status?text??
    45. ????????statustxt.css('color','#000');?//initial?color?of?status?text??
    46. ??????????
    47. ????},??
    48. ????uploadProgress:?function(event,?position,?total,?percentComplete)?{?//on?progress??
    49. ????????progressbar.width(percentComplete?+?'%')?//update?progressbar?percent?complete??
    50. ????????statustxt.html(percentComplete?+?'%');?//update?status?text??
    51. ????????if(percentComplete>50)??
    52. ????????????{??
    53. ????????????????statustxt.css('color','#fff');?//change?status?text?to?white?after?50%??
    54. ????????????}else{??
    55. ????????????????statustxt.css('color','#000');??
    56. ????????????}??
    57. ??????????????
    58. ????????},??
    59. ????complete:?function(response)?{?//?on?complete??
    60. ????????output.html(response.responseText);?//update?element?with?received?data??
    61. ????????myform.resetForm();??//?reset?form??
    62. ????????submitbutton.removeAttr('disabled');?//enable?submit?button??
    63. ????????progressbox.hide();?//?hide?progressbar??
    64. ????????$("#uploaderform").slideUp();?//?hide?form?after?upload??
    65. ????}??
    66. });??
    67. ??
    68. });???
    69. ???

    ?uoload.php

    ?

    PHP Code
    1. ??
    2. ??
    3. //If?you?face?any?errors,?increase?values?of?"post_max_size",?"upload_max_filesize"?and?"memory_limit"?as?required?in?php.ini??
    4. ??
    5. ?//Some?Settings??
    6. $ThumbSquareSize????????=?200;?//Thumbnail?will?be?200x200??
    7. $BigImageMaxSize????????=?500;?//Image?Maximum?height?or?width??
    8. $ThumbPrefix????????????=?"thumb_";?//Normal?thumb?Prefix??
    9. $DestinationDirectory???=?'../upload/';?//Upload?Directory?ends?with?/?(slash)??
    10. $Quality????????????????=?90;??
    11. ??
    12. //ini_set('memory_limit',?'-1');?//?maximum?memory!??
    13. ??
    14. foreach($_FILES?as?$file)??
    15. {??
    16. //?some?information?about?image?we?need?later.??
    17. $ImageName??????=?$file['name'];??
    18. $ImageSize??????=?$file['size'];??
    19. $TempSrc????????=?$file['tmp_name'];??
    20. $ImageType??????=?$file['type'];??
    21. ??
    22. ??
    23. if?(is_array($ImageName))???
    24. {??
    25. ????$c?=?count($ImageName);??
    26. ??????
    27. ????echo??'
        '
      ;??
    28. ??????
    29. ????for?($i=0;?$i?$c;?$i++)??
    30. ????{??
    31. ????????$processImage???????????=?true;???
    32. ????????$RandomNumber???????????=?rand(0,?9999999999);??//?We?need?same?random?name?for?both?files.??
    33. ??????????
    34. ????????if(!isset($ImageName[$i])?||?!is_uploaded_file($TempSrc[$i]))??
    35. ????????{??
    36. ????????????echo?'
      Error?occurred?while?trying?to?process?'.$ImageName[$i].',?may?be?file?too?big!
      '
      ;?//output?error??
    37. ????????}??
    38. ????????else??
    39. ????????{??
    40. ????????????//Validate?file?+?create?image?from?uploaded?file.??
    41. ????????????switch(strtolower($ImageType[$i]))??
    42. ????????????{??
    43. ????????????????case?'image/png':??
    44. ????????????????????$CreatedImage?=?imagecreatefrompng($TempSrc[$i]);??
    45. ????????????????????break;??
    46. ????????????????case?'image/gif':??
    47. ????????????????????$CreatedImage?=?imagecreatefromgif($TempSrc[$i]);??
    48. ????????????????????break;??
    49. ????????????????case?'image/jpeg':??
    50. ????????????????case?'image/pjpeg':??
    51. ????????????????????$CreatedImage?=?imagecreatefromjpeg($TempSrc[$i]);??
    52. ????????????????????break;??
    53. ????????????????default:??
    54. ????????????????????$processImage?=?false;?//image?format?is?not?supported!??
    55. ????????????}??
    56. ????????????//get?Image?Size??
    57. ????????????list($CurWidth,$CurHeight)=getimagesize($TempSrc[$i]);??
    58. ??
    59. ????????????//Get?file?extension?from?Image?name,?this?will?be?re-added?after?random?name??
    60. ????????????$ImageExt?=?substr($ImageName[$i],?strrpos($ImageName[$i],?'.'));??
    61. ????????????$ImageExt?=?str_replace('.','',$ImageExt);??
    62. ??????
    63. ????????????//Construct?a?new?image?name?(with?random?number?added)?for?our?new?image.??
    64. ????????????$NewImageName?=?$RandomNumber.'.'.$ImageExt;??
    65. ??
    66. ????????????//Set?the?Destination?Image?path?with?Random?Name??
    67. ????????????$thumb_DestRandImageName????=?$DestinationDirectory.$ThumbPrefix.$NewImageName;?//Thumb?name??
    68. ????????????$DestRandImageName??????????=?$DestinationDirectory.$NewImageName;?//Name?for?Big?Image??
    69. ??
    70. ????????????//Resize?image?to?our?Specified?Size?by?calling?resizeImajquery php多资料上传

      声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

    相关文章

    相关视频


    网友评论

    文明上网理性发言,请遵守 新闻评论服务协议

    我要评论
  • jquery php多资料上传
  • 专题推荐

    作者信息
    jquery php多资料上传

    认证0级讲师

    推荐视频教程
  • jquery php多资料上传javascript初级视频教程
  • jquery php多资料上传jquery 基础视频教程
  • 视频教程分类
    相关标签: lt Image gt CurHeight CurWidth

    上一篇: php给一组指定关键词添加span标签的方法

    下一篇: 文件自动备份软件

    推荐阅读