91精品综合久久久久久五月天_国产精品一区电影_中文字幕欧美日韩一区二区_亚洲一区二区三区精品动漫

PHP file upload handling class

Last night of PHP's file upload side of things, got more than 3:00, and finally come up with the file upload handling class. Wrote a half last night, then the rest of the afternoon finish. Tested for a moment did not find any problems. Including the bulk upload file, add watermark to images, generate image thumbnails and other features, accessories directory can use the custom format the date parameters. First posted the code to share it:
PHP Code

   1. <? Php
   2. //-------------------------------------
   3. / / Document Description: file upload handling class
   4. / / File of: Jesse Lee
   5. / / On the home page: http://www.lisijie.com.cn
   6. / / Last Updated :2008-5-14
   7. //-------------------------------------
   8.
   9. Class upload (
  10.
  11. Var $ dir; / / accessories store physical directory
  12. Var $ time; / / custom file upload time
  13. Var $ allow_types; / / allow upload attachment type
  14. Var $ field; / / upload control name
  15. Var $ maxsize; / / maximum allowed file size in KB
  16.
  17. Var $ thumb_width; / / Thumbnail width
  18. Var $ thumb_height; / / the thumbnail height
  19.
  20. Var $ watermark_file; / / watermark image address
  21. Var $ watermark_pos; / / position of watermark
  22. Var $ watermark_trans; / / watermark transparency
  23.
  24.
  25. / / Constructor
  26. / / $ Types: allowed upload file types, $ maxsize: Allow size, $ field: From the control name, $ time: time for a custom upload
  27. Function upload ($ types = 'jpg | png', $ maxsize = 1024, $ field = 'attach', $ time ='') (
  28. $ This-> allow_types = explode ('|',$ types);
  29. $ This-> maxsize = $ maxsize * 1024;
  30. $ This-> field = $ field;
  31. $ This-> time = $ time? $ Time: time ();
  32.)
  33.
  34. / / Set and create a file stored in the directory specific
  35. / / $ Basedir: base directory must be the physical path
  36. / / $ Filedir: custom subdirectories, available parameters (y), (m), (d)
  37. Function set_dir ($ basedir, $ filedir ='') (
  38. $ Dir = $ basedir;
  39.! Is_dir ($ dir) & & @ mkdir ($ dir, 0777);
  40. If (! Empty ($ filedir)) (
  41. $ Filedir = str_replace (array ('(y }','{ m }','{ d)'), array (date ('Y', $ this-> time), date ('m', $ this-> time), date ('d', $ this-> time)), strtolower ($ filedir));
  42. $ Dirs = explode ('/',$ filedir);
  43. Foreach ($ dirs as $ d) (
  44.! Empty ($ d) & & $ dir .= $ d. '/';
  45.! Is_dir ($ dir) & & @ mkdir ($ dir, 0777);
  46.)
  47.)
  48. $ This-> dir = $ dir;
  49.)
  50.
  51. / / Image thumbnail settings, if you do not generate thumbnails is not set
  52. / / $ Width: thumbnail width, $ height: height Thumbnail
  53. Function set_thumb ($ width = 0, $ height = 0) (
  54. $ This-> thumb_width = $ width;
  55. $ This-> thumb_height = $ height;
  56.)
  57.
  58. / / Image watermark setting, if you do not add the watermark is not set to generate
  59. / / $ File: watermark image, $ pos: position of watermark, $ trans: watermark transparency
  60. Function set_watermark ($ file, $ pos = 6, $ trans = 80) (
  61. $ This-> watermark_file = $ file;
  62. $ This-> watermark_pos = $ pos;
  63. $ This-> watermark_trans = $ trans;
  64.)
  65.
  66. /*---------------------------------------------- ------------------
  67. The implementation of file upload, processed returns a success or failure of the file upload information array
  68. Including: name for the file name, upload is successfully uploaded to the server when the file name, upload failure is a local file name
  69. Dir for the server storing the physical path of the attachment, upload failure the value does not exist
  70. Size as the attachment size, upload the value does not exist fail
  71. Flag for the state identification, 1 for success, -1, said file type not allowed, said the file size exceeds -2
  72. ------------------------------------------------ -----------------*/
  73. Function execute () (
  74. $ Files = array (); / / successfully uploaded the file information
  75. $ Field = $ this-> field;
  76. $ Keys = array_keys ($ _FILES [$ field] ['name']);
  77. Foreach ($ keys as $ key) (
  78. If (! $ _FILES [$ Field] ['name'] [$ key]) continue;
  79.
  80. $ Fileext = $ this-> fileext ($ _FILES [$ field] ['name'] [$ key]); / / Get the file extension
  81. $ Filename = date ('Ymdhis', $ this-> time). Mt_rand (10,99 ).'.'.$ fileext; / / generate file name
  82. $ Filedir = $ this-> dir; / / Annex actual store directory
  83. $ Filesize = $ _FILES [$ field] ['size'] [$ key]; / / File Size
  84.
  85. / / File type not allowed
  86. If (! In_array ($ fileext, $ this-> allow_types)) (
  87. $ Files [$ key] ['name'] = $ _FILES [$ field] ['name'] [$ key];
  88. $ Files [$ key] ['flag'] = -1;
  89. Continue;
  90.)
  91.
  92. / / The file size exceeds
  93. If ($ filesize> $ this-> maxsize) (
  94. $ Files [$ key] ['name'] = $ _FILES [$ field] ['name'] [$ key];
  95. $ Files [$ key] ['name'] = $ filesize;
  96. $ Files [$ key] ['flag'] = -2;
  97. Continue;
  98.)
  99.
 100. $ Files [$ key] ['name'] = $ filename;
 101. $ Files [$ key] ['dir'] = $ filedir;
 102. $ Files [$ key] ['size'] = $ filesize;
 103.
 104. / / Save the uploaded file and delete temporary files
 105. If (is_uploaded_file ($ _FILES [$ field] ['tmp_name'] [$ key])) (
 106. Move_uploaded_file ($ _FILES [$ field] ['tmp_name'] [$ key], $ filedir. $ Filename);
 107. @ Unlink ($ _FILES [$ field] ['tmp_name'] [$ key]);
 108. $ Files [$ key] ['flag'] = 1;
 109.
 110. / / Add a watermark on pictures and generate thumbnails
 111. If (in_array ($ fileext, array ('jpg', 'png'))) (
 112. If ($ this-> thumb_width) (
 113. If ($ this-> create_thumb ($ filedir. $ Filename, $ filedir. 'Thumb_'. $ Filename)) (
 114. $ Files [$ key] ['thumb'] = 'thumb_'. $ Filename; / / thumbnail file name
 115.)
 116.)
 117. $ This-> create_watermark ($ filedir. $ Filename);
 118.)
 119.)
 120.)
 121.
 122. Return $ files;
 123.)
 124.
 125. / / Create thumbnails, generate the same extension Thumbnail
 126. / / $ Src_file: source image path, $ thumb_file: Thumbnail Path
 127. Function create_thumb ($ src_file, $ thumb_file) (
 128. $ T_width = $ this-> thumb_width;
 129. $ T_height = $ this-> thumb_height;
 130.
 131. If (! File_exists ($ src_file)) return false;
 132.
 133. $ Src_info = getImageSize ($ src_file);
 134.
 135. / / If the source image is less than or equal to the copy of the source image as a thumbnail thumbnail
 136. If ($ src_info [0] <= $ t_width & & $ src_info [1] <= $ t_height) (
 137. If (! Copy ($ src_file, $ thumb_file)) (
 138. Return false;
 139.)
 140. Return true;
 141.)
 142.
 143. / / Thumbnail size pro-rata basis
 144. If ($ src_info [0] - $ t_width> $ src_info [1] - $ t_height) (
 145. $ T_height = ($ t_width / $ src_info [0]) * $ src_info [1];
 146.) Else (
 147. $ T_width = ($ t_height / $ src_info [1]) * $ src_info [0];
 148.)
 149.
 150. / / Get file extension
 151. $ Fileext = $ this-> fileext ($ src_file);
 152.
 153. Switch ($ fileext) (
 154. Case 'jpg':
 155. $ Src_img = ImageCreateFromJPEG ($ src_file); break;
 156. Case 'png':
 157. $ Src_img = ImageCreateFromPNG ($ src_file); break;
 158. Case 'gif':
 159. $ Src_img = ImageCreateFromGIF ($ src_file); break;
 160.)
 161.
 162. / / Create a true color of the thumbnail image
 163. $ Thumb_img = @ ImageCreateTrueColor ($ t_width, $ t_height);
 164.
 165. / / ImageCopyResampled copy of the image smoothness function better, giving priority to
 166. If (function_exists ('imagecopyresampled')) (
 167. @ ImageCopyResampled ($ thumb_img, $ src_img, 0,0,0,0, $ t_width, $ t_height, $ src_info [0], $ src_info [1]);
 168.) Else (
 169. @ ImageCopyResized ($ thumb_img, $ src_img, 0,0,0,0, $ t_width, $ t_height, $ src_info [0], $ src_info [1]);
 170.)
 171.
 172. / / Generate thumbnail
 173. Switch ($ fileext) (
 174. Case 'jpg':
 175. ImageJPEG ($ thumb_img, $ thumb_file); break;
 176. Case 'gif':
 177. ImageGIF ($ thumb_img, $ thumb_file); break;
 178. Case 'png':
 179. ImagePNG ($ thumb_img, $ thumb_file); break;
 180.)
 181.
 182. / / Destroy the temporary image
 183. @ ImageDestroy ($ src_img);
 184. @ ImageDestroy ($ thumb_img);
 185.
 186. Return true;
 187.
 188.)
 189.
 190. / / Add a watermark to images
 191. / / $ File: the file you want to add watermark
 192. Function create_watermark ($ file) (
 193.
 194. / / File does not exist is returned
 195. If (! File_exists ($ this-> watermark_file) | |! File_exists ($ file)) return;
 196. If (! Function_exists ('getImageSize')) return;
 197.
 198. / / Check GD supported file types
 199. $ Gd_allow_types = array ();
 200. If (function_exists ('ImageCreateFromGIF')) $ gd_allow_types ['image / gif'] = 'ImageCreateFromGIF';
 201. If (function_exists ('ImageCreateFromPNG')) $ gd_allow_types ['image / png'] = 'ImageCreateFromPNG';
 202. If (function_exists ('ImageCreateFromJPEG')) $ gd_allow_types ['image / jpeg'] = 'ImageCreateFromJPEG';
 203.
 204. / / Get file information
 205. $ Fileinfo = getImageSize ($ file);
 206. $ Wminfo = getImageSize ($ this-> watermark_file);
 207.
 208. If ($ fileinfo [0] <$ wminfo [0] | | $ fileinfo [1] <$ wminfo [1]) return;
 209.
 210. If (array_key_exists ($ fileinfo ['mime'], $ gd_allow_types)) (
 211. If (array_key_exists ($ wminfo ['mime'], $ gd_allow_types)) (
 212.
 213. / / Create the image from the file
 214. $ Temp = $ gd_allow_types [$ fileinfo ['mime']]($ file);
 215. $ Temp_wm = $ gd_allow_types [$ wminfo ['mime']]($ this-> watermark_file);
 216.
 217. / / Position of watermark
 218. Switch ($ this-> watermark_pos) (
 219. Case 1: / / at the top of the left hand side
 220. $ Dst_x = 0; $ dst_y = 0; break;
 221. Case 2: / / top center
 222. $ Dst_x = ($ fileinfo [0] - $ wminfo [0]) / 2; $ dst_y = 0; break;
 223. Case 3: / / top right hand side
 224. $ Dst_x = $ fileinfo [0]; $ dst_y = 0; break;
 225. Case 4: / / bottom left hand side
 226. $ Dst_x = 0; $ dst_y = $ fileinfo [1]; break;
 227. Case 5: / / bottom of the center
 228. $ Dst_x = ($ fileinfo [0] - $ wminfo [0]) / 2; $ dst_y = $ fileinfo [1]; break;
 229. Case 6: / / bottom right hand side
 230. $ Dst_x = $ fileinfo [0] - $ wminfo [0]; $ dst_y = $ fileinfo [1] - $ wminfo [1]; break;
 231. Default: / / Random
 232. $ Dst_x = mt_rand (0, $ fileinfo [0] - $ wminfo [0]); $ dst_y = mt_rand (0, $ fileinfo [1] - $ wminfo [1]);
 233.)
 234.
 235. If (function_exists ('ImageAlphaBlending')) ImageAlphaBlending ($ temp_wm, True); / / set the blending mode of the image
 236. If (function_exists ('ImageSaveAlpha')) ImageSaveAlpha ($ temp_wm, True); / / save the full alpha channel information
 237.
 238. / / Add a watermark to images
 239. If (function_exists ('imageCopyMerge')) (
 240. ImageCopyMerge ($ temp, $ temp_wm, $ dst_x, $ dst_y, 0,0, $ wminfo [0], $ wminfo [1], $ this-> watermark_trans);
 241.) Else (
 242. ImageCopyMerge ($ temp, $ temp_wm, $ dst_x, $ dst_y, 0,0, $ wminfo [0], $ wminfo [1]);
 243.)
 244.
 245. / / Save the image
 246. Switch ($ fileinfo ['mime']) (
 247. Case 'image / jpeg':
 248. @ ImageJPEG ($ temp, $ file);
 249. Break;
 250. Case 'image / png':
 251. @ ImagePNG ($ temp, $ file);
 252. Break;
 253. Case 'image / gif':
 254. @ ImageGIF ($ temp, $ file);
 255. Break;
 256.)
 257. / / Destroy the image zero
 258. @ ImageDestroy ($ temp);
 259. @ ImageDestroy ($ temp_wm);
 260.)
 261.)
 262.)
 263.
 264. / / Get the file extension
 265. Function fileext ($ filename) (
 266. Return strtolower (substr (strrchr ($ filename ,'.'), 1,10));
 267.)
 268.)
 269.?>

Use examples:
PHP Code

   1. <? Php
   2. If ($ _GET ['action'] == 'save') (
   3.
   4. $ Up = new upload ();
   5. $ Up-> set_dir (dirname (__FILE__). '/ Upload /','{ y) / (m)');
   6. $ Up-> set_thumb (100,80);
   7. $ Up-> set_watermark (dirname (__FILE__). '/ Jblog / images / watermark.png', 6,90);
   8. $ Fs = $ up-> execute ();
   9.
  10. Var_dump ($ fs);
  11.)
  12.?>
  13. <html>
  14. <head> <title> Test </ title> </ head>
  15. <body Style="margin:0;padding:0">
  16. <form Name="upload" method="post" action="?action=save" enctype="multipart/form-data" style="margin:0">
  17. <input Type="file" name="attach[]" />
  18. <input Type="file" name="attach[]" />
  19. <input Type="submit" name="submit" value="上傳" />
  20. </ Form>
  21. </ Body>
  22. </ Html>

Declined comment

91精品综合久久久久久五月天_国产精品一区电影_中文字幕欧美日韩一区二区_亚洲一区二区三区精品动漫
欧美中文字幕在线观看视频| 91精品久久久久久久久久久久久久| 自拍另类欧美| 99精品国产高清在线观看| 成人黄色中文字幕| 97久久伊人激情网| 国产精品12p| 久久久久久久色| 日韩在线播放视频| 久久视频中文字幕| 国产精品美女久久久久av福利| 国产精品视频地址| 欧美另类在线播放| 欧美激情一级二级| 亚洲日本理论电影| 日本一区二区三区免费观看 | 69国产精品成人在线播放| 国产二级片在线观看| 日韩视频免费在线观看| 国产精品久久久久久久免费大片| 欧美激情18p| 日本一区视频在线观看| 男人天堂成人在线| www.九色.com| 国产成人av在线播放| 国产精品无码一本二本三本色| 久久综合久中文字幕青草| 亚洲最大激情中文字幕| 日本不卡久久| 国产精品制服诱惑| 久久久免费电影| 国产精品视频网| 亚洲人成网站在线播放2019| 日本手机在线视频| 国产一区 在线播放| 久久免费看av| 九色精品免费永久在线| 午夜精品一区二区三区在线视频| 欧美极品日韩| 成人免费观看毛片| 久久国产午夜精品理论片最新版本| 国产精品视频yy9099| 一级做a爰片久久| 欧美中文字幕在线视频| 成人av在线亚洲| 国产精品无av码在线观看| 亚洲欧洲精品一区二区三区波多野1战4| 日本亚洲欧洲色α| 国产欧美精品va在线观看| 久久综合亚洲精品| 九九久久国产精品| 欧美成人精品欧美一级乱| 69**夜色精品国产69乱| 精品国产区在线| 日韩精品一区二区三区色偷偷| 国产精品自拍合集| 国产精品美女视频网站| 日本精品一区二区| 97久久精品人搡人人玩| 国产精品久久久久久久久影视| 天堂资源在线亚洲资源| 国产免费一区二区三区在线能观看| 日日骚久久av| 日韩有码免费视频| 福利视频一二区| 精品国产一区二区三区麻豆小说 | 精品一区日韩成人| 久久精品女人的天堂av| 麻豆国产精品va在线观看不卡| 欧美性受xxxx黑人猛交88| 91精品国产91久久| 一本色道久久综合亚洲二区三区| 激情小说综合网| 国产成人三级视频| 欧美一级黄色影院| 久久精品香蕉视频| 欧美一区二区三区精品电影| av一区二区三区四区电影| 欧美乱大交xxxxx| 国产一区二区三区乱码| 久久福利网址导航| 国内精品中文字幕| 国产精品久久久久av福利动漫| 日韩精品一区二区免费| 久久精品日产第一区二区三区 | 国产日韩欧美在线| 国产精品日韩在线观看| 欧美视频小说| 国产精品免费一区二区三区| 欧美理论一区二区| 国产精品网站视频| 黄色影视在线观看| 国产精品人人妻人人爽人人牛| 日韩一级免费看| 久久www免费人成精品| 日韩三级在线播放| 日韩一区二区三区在线播放| 欧美影视一区二区| 国产精品视频免费观看www| 欧美性受xxx| 久久天天躁夜夜躁狠狠躁2022| 国产日韩欧美在线| 一本二本三本亚洲码| 久久久一本二本三本| 日本精品一区二区三区在线| 久久久久久一区| 欧美亚洲黄色片| 国产精品第1页| 精品少妇人欧美激情在线观看 | 99精品99久久久久久宅男| 亚洲欧洲一区二区福利| 国产成人精品日本亚洲专区61| 操人视频在线观看欧美| 美女视频久久黄| 欧美精品制服第一页| 国产无限制自拍| 中文字幕一区二区三区四区五区六区 | 麻豆91蜜桃| 欧美精品www| 久久久亚洲精品视频| 人人妻人人澡人人爽欧美一区 | 色与欲影视天天看综合网| 成人免费在线一区二区三区| 亚洲欧美日韩精品在线| 久久人人97超碰精品888| 欧美精品一区二区三区在线看午夜| 欧美巨大黑人极品精男| 97干在线视频| 欧美日韩国产综合视频在线| 国产aⅴ夜夜欢一区二区三区| 久久久久狠狠高潮亚洲精品| 欧美日本国产精品| 亚洲影影院av| 久久天堂电影网| 99国产盗摄| 黄色国产小视频| 性欧美亚洲xxxx乳在线观看| 国产精品久久久久久久久久ktv| 97国产在线观看| 欧美精品一区免费| 一区二区日本伦理| 国产精品久久久久久久久免费看 | 国产精品丝袜高跟| 99视频在线免费| 欧美高清中文字幕| 亚洲国产一区二区三区在线| 国产精品日韩专区| 国产成人精品久久二区二区91| 国产一区二区网| 欧美又大又粗又长| 亚洲精品欧洲精品| 国产精品久久久久久久久久久久午夜片 | 午夜精品亚洲一区二区三区嫩草| 国产精品色视频| 久久天天狠狠| 国产另类自拍| 国产一级黄色录像片| 欧美尤物巨大精品爽| 亚洲日本精品一区| 欧美精品午夜视频| 久久视频精品在线| 久久久久久有精品国产| 99久久久久国产精品免费| 国产中文字幕在线免费观看| 欧美亚洲午夜视频在线观看| 日本www在线视频| 亚洲 中文字幕 日韩 无码| 欧美成人一区二区三区电影| 国产精品区一区二区三在线播放| 国产mv久久久| www黄色在线| 国产精品永久免费| 国产美女视频免费| 国产一区二区免费在线观看| 免费看欧美一级片| 国内精品一区二区三区四区| 欧美伊久线香蕉线新在线| 日韩欧美99| 青草青草久热精品视频在线观看| 日本高清视频精品| 日本欧美一二三区| 日韩中文字幕组| 三级网在线观看| 日韩videos| 日本免费一级视频| 日本午夜在线亚洲.国产| 日本在线高清视频一区| 日本精品一区二区三区四区| 日韩欧美一区二区三区久久婷婷 | 日韩中文字幕在线观看| 国产成人在线播放| 国产二级片在线观看| 久久久久久久av| 国产精品欧美在线| 国产精品久久久久久久久电影网 | 国产精品国产三级国产aⅴ9色| 国产精品美女呻吟| 欧美日韩成人免费| 亚洲欧洲国产日韩精品| 日日噜噜夜夜狠狠久久丁香五月|