??????"uploadResults">??????"center"?style="margin:20px;">"#"">
当前位置:Gxlcms > PHP教程 > jqueryphp多资料上传

jqueryphp多资料上传

时间:2021-07-01 10:21:17 帮助过:4人阅读

jquery php多文件上传

多文件上传

演示

?

index.php

PHP Code

  1. "uploaderform">??
  2. ??
  3. ??
  4. "uploadResults">??
  5. ????"center"?style="margin:20px;">"#"?id="ShowForm">打开/隐藏?表单??
  6. ????"output">??
  7. ??

js文件

JavaScript Code

  1. ???

?uoload.php

?

PHP Code

  1. "center">"index.php">Go?Back?To?Upload?Form??
  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??'
      ';??
    • ??????
    • ????for?($i=0;?$i?$c;?$i++)??
    • ????{??
    • ????????$processImage???????????=?true;???
    • ????????$RandomNumber???????????=?rand(0,?9999999999);??//?We?need?same?random?name?for?both?files.??
    • ??????????
    • ????????if(!isset($ImageName[$i])?||?!is_uploaded_file($TempSrc[$i]))??
    • ????????{??
    • ????????????echo?'Error?occurred?while?trying?to?process?'.$ImageName[$i].',?may?be?file?too?big!';?//output?error??
    • ????????}??
    • ????????else??
    • ????????{??
    • ????????????//Validate?file?+?create?image?from?uploaded?file.??
    • ????????????switch(strtolower($ImageType[$i]))??
    • ????????????{??
    • ????????????????case?'image/png':??
    • ????????????????????$CreatedImage?=?imagecreatefrompng($TempSrc[$i]);??
    • ????????????????????break;??
    • ????????????????case?'image/gif':??
    • ????????????????????$CreatedImage?=?imagecreatefromgif($TempSrc[$i]);??
    • ????????????????????break;??
    • ????????????????case?'image/jpeg':??
    • ????????????????case?'image/pjpeg':??
    • ????????????????????$CreatedImage?=?imagecreatefromjpeg($TempSrc[$i]);??
    • ????????????????????break;??
    • ????????????????default:??
    • ????????????????????$processImage?=?false;?//image?format?is?not?supported!??
    • ????????????}??
    • ????????????//get?Image?Size??
    • ????????????list($CurWidth,$CurHeight)=getimagesize($TempSrc[$i]);??
    • ??
    • ????????????//Get?file?extension?from?Image?name,?this?will?be?re-added?after?random?name??
    • ????????????$ImageExt?=?substr($ImageName[$i],?strrpos($ImageName[$i],?'.'));??
    • ????????????$ImageExt?=?str_replace('.','',$ImageExt);??
    • ??????
    • ????????????//Construct?a?new?image?name?(with?random?number?added)?for?our?new?image.??
    • ????????????$NewImageName?=?$RandomNumber.'.'.$ImageExt;??
    • ??
    • ????????????//Set?the?Destination?Image?path?with?Random?Name??
    • ????????????$thumb_DestRandImageName????=?$DestinationDirectory.$ThumbPrefix.$NewImageName;?//Thumb?name??
    • ????????????$DestRandImageName??????????=?$DestinationDirectory.$NewImageName;?//Name?for?Big?Image??
    • ??
    • ????????????//Resize?image?to?our?Specified?Size?by?calling?resizeIma

人气教程排行