日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
五分鐘PHP上傳類實(shí)現(xiàn)

PHP有很多值得學(xué)習(xí)的地方,這里我們主要介紹PHP上傳類的解決方案,希望大家通過本文有大的收獲。用戶可以直接在WEB頁面中輸入PHP命令代碼,因而不需要任何特殊的開發(fā)環(huán)境。在WEB頁面中,所有PHP代碼都被放置在“”中。此外,用戶還可以選擇使用諸如 等的形式。PHP引擎會自動識別并處理頁面中所有位于PHP定界符之間的代碼。

#T#PHP腳本語言的語法結(jié)構(gòu)與C語言和Perl語言的語法風(fēng)格非常相似。用戶在使用變量前不需要對變量進(jìn)行聲明。使用PHP創(chuàng)建數(shù)組的過程也非常簡單。PHP還具有基本的面向?qū)ο蠼M件功能,可以極大的方便用戶有效組織和封裝自己編寫的代碼,下面我們就詳細(xì)的介紹PHP上傳類的問題。
 
PHP上傳類實(shí)現(xiàn)代碼:

 
 
  1. /**  
  2. *Fileuploadclass  
  3. *@version1.0.0(ThuAug1801:32:39CST2005)  
  4. *@authorsanshi  
  5. */  
  6. classupLoad  
  7. {  
  8. /**  
  9. *  
  10. *@authorsanshi  
  11. *@version1.0.0ThuAug1801:00:18CST2005  
  12. *@paramstring$info文件內(nèi)容  
  13. *@paramstring$fileName生成的文件名  
  14. *@returnboolean建立成功返回true  
  15. *@deprecated  
  16. *建立html文件  
  17. */  
  18. functioncreateHtml($info,$fileName)  
  19. {  
  20. }  
  21. /**  
  22. *  
  23. *@authorsanshi  
  24. *@version1.0.0ThuAug1801:03:09CST2005  
  25. *@returnvoid  
  26. *@deprecated  
  27. *構(gòu)造函數(shù)  
  28. */  
  29. functiondownLoad()  
  30. {}  
  31. /**  
  32. *  
  33. *@authorsanshi  
  34. *@version1.0.0ThuAug1801:03:55CST2005  
  35. *@paramstring$fileField在表單中的字段名  
  36. *@paramstring$length限制的長度  
  37. *@returnboolean成功返回true  
  38. *@deprecated  
  39. *功能實(shí)現(xiàn)函數(shù)  
  40. */  
  41. functioninit($fileField,$length='')  
  42. {  
  43. $files=$_FILES[$fileField];  
  44. //用戶名需要改動,根據(jù)自己的實(shí)際情況做改動  
  45. $userName='sanshi';  
  46. $fileName=$files['name'];  
  47. $fileType=$files['type'];  
  48. $fileTemp=$files['tmp_name'];  
  49. $fileSize=empty($length)?($files['size']+10):$length;  
  50. $fileError=$files['error'];//這塊也許php4中沒有  
  51. //改為  
  52. //if($this->_isType($fileName)||$this->_isBig($length ))  
  53. if(!$this->_isType($fileName)||$this->_isBig($length )||$fileError!=0)  
  54. {  
  55. //print_r($files);  
  56. returnfalse;  
  57. }else{  
  58. $path=$this->_createDir($userName);//取得路徑  
  59. $createFileName=$userName."_".time();//設(shè)置當(dāng)前文件名  
  60. $createFileType=$this->getFileType($fileName);//設(shè)置文件類別  
  61. return@move_uploaded_file($fileTemp,$path.$createFileName.'.'.$createFileType)?true:false;  
  62. }  
  63. }  
  64.  
  65. /**  
  66. *  
  67. *@authorsanshi  
  68. *@version1.0.0ThuAug1801:07:43CST2005  
  69. *@paramint$length上傳限制的大小  
  70. *@returnboolean超過返回true  
  71. *@deprecated  
  72. *判斷是否超過預(yù)定大小  
  73. */  
  74. function_isBig($length)  
  75. {  
  76. $bigest='';  
  77. return$big>$bigest?true:false;  
  78. }  
  79. /**  
  80. *  
  81. *@authorsanshi  
  82. *@version1.0.0ThuAug1801:08:55CST2005  
  83. *@paramstring$fileName文件名  
  84. *@returnstring$fileType文件后綴  
  85. *@deprecated  
  86. *取得文件后綴(只取得文件的***一個后綴名)  
  87. */  
  88. functiongetFileType($fileName)  
  89. {  
  90. returnend(explode('.',$fileName));  
  91. }  
  92. /**  
  93. *  
  94. *@authorsanshi  
  95. *@version1.0.0ThuAug1801:10:41CST2005  
  96. *@paramstring$fileName文件名  
  97. *@paramboolean$method是否檢查多個后綴默認(rèn)false  
  98. *@paramint$postFix后綴個數(shù)默認(rèn)為2  
  99. *@returnboolean存在返回true  
  100. *@deprecated  
  101. *檢查文件的后綴是否在類別數(shù)組中,類別數(shù)組自己設(shè)置  
  102. *如果$method設(shè)置為true則檢查文件有幾個后綴  
  103. */  
  104. function_isType($fileName,$method='false',$postFix=2)  
  105. {  
  106. //設(shè)置類別數(shù)組  
  107. $type=array('jpeg',  
  108. 'gif',  
  109. 'bmp',  
  110. 'exe');  
  111. $fileName=strtolower($fileName);  
  112. $fileTypeArray=explode('.',$fileName);  
  113. $fileType=end($fileTypeArray);  
  114. //判斷是否有一個文件有多個后綴  
  115. if($method)  
  116. {  
  117. if(count($fileTypeArray)>(is_int($postFix)?$postFix:2))  
  118. {  
  119. returnfalse;  
  120. }  
  121. }  
  122. returnin_array($fileType,$type);  
  123. }  
  124.  
  125. /**  
  126. *  
  127. *@authorsanshi  
  128. *@version1.0.0ThuAug1801:17:19CST2005  
  129. *@paramstring$userName  
  130. *@returnstring$path  
  131. *@deprecated  
  132. *建立目錄目錄格式年/月/日/用戶名/  
  133. *權(quán)限為755  
  134. */  
  135. function_createDir($userName)  
  136. {  
  137. $root='';  
  138. $pathSign=DIRECTORY_SEPARATOR;  
  139. $y=date('Y').$pathSign;  
  140. $m=date('m').$pathSign;  
  141. $d=date('d').$pathSign;  
  142. $path=$root.$y.$m.$d.$userName;  
  143. $dirArray=explode($pathSign,$path);  
  144. $tempDir='';  
  145. foreach($dirArrayas$dir)  
  146. {  
  147. $tempDir.=$dir.$pathSign;  
  148. $isFile=file_exists($tempDir);  
  149. clearstatcache();  
  150. if(!$isFile&&!is_dir($tempDir))  
  151. {  
  152. @mkdir($tempDir,0755);  
  153. }  
  154. }  
  155. return$path.$pathSign;  
  156. }  
  157. /**  
  158. *  
  159. *@authorsanshi  
  160. *@version1.0.0ThuAug1801:19:32CST2005  
  161. *@param string$dirName目錄名  
  162. *@return boolean可以操作返回true  
  163. *@deprecated  
  164. *判斷操作是否在上傳目錄  
  165. */  
  166. function_isDel($dirName)  
  167. {  
  168. //注意upLoadDir,一定要與真正使用目錄相對應(yīng)  
  169. $upLoadDir='';  
  170. $upLoadDir=preg_replace('/\\//','\/',$upLoadDir);  
  171. $format="/^{$upLoadDir}/";  
  172. returnpreg_match($format,$dirName);  
  173. }  
  174. /**  
  175. *  
  176. *@authorsanshi  
  177. *@version1.0.0ThuAug1801:25:58CST2005  
  178. *@paramstring$fileName文件名  
  179. *@returnboolean刪除文件成功返回true  
  180. *@deprecated  
  181. *刪除文件  
  182. */  
  183. functiondelFile($fileName)  
  184. {  
  185. $cur_dir=dirname(trim($fileName));  
  186. if($this->_isDel($cur_dir))  
  187. {  
  188. return@unlink($fileName)?true:false;  
  189. }else{  
  190. returnfalse;  
  191. }  
  192. }  
  193. /**  
  194. *  
  195. *@authorsanshi  
  196. *@version1.0.0ThuAug1801:27:43CST2005  
  197. *@paramstring$dieName目錄名  
  198. *@returnboolean刪除成功返回true  
  199. *@deprecated  
  200. *刪除目錄目錄下如果有文件不能刪除  
  201. */  
  202. functiondelDir($dirName)  
  203. {  
  204. if($this->_isDel($dirName)&&is_dir($dirName))  
  205. {  
  206. return@rmdir($dirName)?true:false;  
  207. }else{  
  208. returnfalse;  
  209. }  
  210. }  
  211.  
  212. }  
  213. ?> 
  214. //使用  
  215. /*  
  216. include'upLoad.class.php';  
  217. $up=newupLoad();  
  218. if($up->init("file"))  
  219. {  
  220. echo'success';  
  221. }else{  
  222. echo'failure';  
  223. }  
  224. */  
  225. ?> 

新聞名稱:五分鐘PHP上傳類實(shí)現(xiàn)
文章轉(zhuǎn)載:http://www.5511xx.com/article/dphhcji.html