PHP上传类实现单个和批量上传
创始人
2024-06-11 19:11:02
0

PHP上传类还是比较常用的,于是我研究了一下PHP上传类,在这里拿出来和大家分享一下,希望对大家有用。PHP本身是一种简单而强大的语言。PHP语言拥有核心特性如强大的字符串和数组处理能力,同时极大的改进了对面向对象编程的支持(PHP5以上版本)。

#T#通过使用标准的和可选的扩展模块,PHP应用程序可以连接MySQL或Oracle等十几种数据库、绘图、创建PDF文件和创建解析XML文件。你也可以使用C语言来写自己的PHP扩展模块。例如,在已存在的代码库中提供一个PHP的接口函数。你也可以在Windows下运行PHP,使用COM控制其它诸如Word和Excel的Windows应用程序,或者使用ODBC来连接数据库。在国内,PHP曾经和微软的ASP并驾齐驱,是大家常用的网络编程语言。 

PHP上传类代码:

  1. /**  
  2. *@packagemyFrameworkuploadclass  
  3. *@Descriptionuploadclass  
  4. *@Date2007-11-28  
  5. *@authorantsnet  
  6. *@copyrighthttp://www.antsnet.net  
  7. *@Emailantsnet@163.com  
  8. *@Environment:Apache2.0.59+PHP5.2.5+mysql5.0  
  9. *@version$Id:myFrame_Upload.php22008-02-2701:14:05ZAdministrator$  
  10. */  
  11. classmyFrame_UploadextendsmyFrame  
  12. {  
  13. var$uploadPath="uploadFile/";  
  14. var$fullPath='';  
  15. var$message;  
  16. var$_debug=false;  
  17. var$errorMessage='';  
  18.  
  19. function__construct($uploadPath='')  
  20. {  
  21. if($uploadPath!="")  
  22. {  
  23. $this->uploadPath=$uploadPath;  
  24. }  
  25. }  
  26. /**  
  27. *Batchupload  
  28. *  
  29. *@paramArray$arrayOutPut  
  30. */  
  31. publicfunctionformLocalBatch($keepSource=false,$arrayOutPut='')  
  32. {  
  33. $returnArray=array();  
  34. if(sizeof($_FILES)==$arrayOutPut&&!$keepSource)  
  35. {  
  36. $i=0;  
  37. foreach($_FILESas$index=>$value)  
  38. {  
  39. $returnArray[]=$this->fromLocal($value,$outPutName[$i]);  
  40. $i++;  
  41. }  
  42. }else{  
  43. foreach($_FILESas$index=>$value)  
  44. {  
  45. $returnArray[]=$this->fromLocal($value);  
  46. }  
  47. }  
  48. return$returnArray;  
  49. }  
  50. /**  
  51. *Uploadfileformlocal  
  52. *  
  53. *@paramArray|String$file_Area_Name  
  54. *@paramArray|String$outPutName  
  55. */  
  56. publicfunctionfromLocal($VALUE,$outPutName='')  
  57. {  
  58.  
  59. include_once(SERVERROOT.MYFRAME.'myFrame_Basic.php');  
  60. /**  
  61. *thefollowingforsingle  
  62. */  
  63. if($outPutName==''||$outPutName=="NULL")  
  64. {  
  65. $outPutName=date("YmdHis");  
  66. }  
  67. if($VALUE['error']>0)  
  68. {  
  69. switch($VALUE['errror'])  
  70. {  
  71. case'1':  
  72. $this->errorMessage[]=$this->myFrameMessage['false']['file']['max'];  
  73. returnfalse;  
  74. break;  
  75. case'2':  
  76. $this->errorMessage[]=$this->myFrameMessage['false']['file']['maxDefined'];  
  77. returnfalse;  
  78. break;  
  79. case'3':  
  80. $this->errorMessage[]=$this->myFrameMessage['false']['file']['uncomplite'];  
  81. returnfalse;  
  82. break;  
  83. case'4':  
  84. $this->errorMessage[]=$this->myFrameMessage['false']['file']['unupload'];  
  85. returnfalse;  
  86. break;  
  87.  
  88. }  
  89. }  
  90. $fileName=$this->uploadPath.$outPutName.myFrame_Basic::getFileName($VALUE['name']).myFrame_Basic::getFileExt($VALUE['name']);  
  91. if(is_uploaded_file($VALUE['tmp_name']))  
  92. {  
  93. if(!move_uploaded_file($VALUE['tmp_name'],$fileName))  
  94. {  
  95. $this->errorMessage[]=$this->myFrameMessage['false']['file']['move'];  
  96. returnfalse;  
  97. }else{  
  98. return$fileName;  
  99. }  
  100. }  
  101. }  
  102. /**  
  103. *Uploadfromnetwork  
  104. *  
  105. *@paramArray|String$url  
  106. *@paramArray|String$outPutName  
  107. *@paramBool$keepSource  
  108. */  
  109. publicfunctionfromNet($url,$outPutName='',$keepSource=false)  
  110. {  
  111. include_once(SERVERROOT.MYFRAME.'myFrame_Basic.php');  
  112. if($outPutName=="")  
  113. {  
  114. $outPutName=date("YmdHis");  
  115. }  
  116. $fileType=myFrame_Basic::getFileExt($url);  
  117. $fileName=$outPutName.$fileType;  
  118. $contents=file_get_contents($url);  
  119. $return=file_put_contents($this->uploadPath.$fileName,$contents);  
  120. if($return){  
  121. $this->fullPath=$this->uploadPath.$fileName;  
  122. return$this->fullPath;  
  123. }else{  
  124. $this->errorMessage[]=$this->myFrameMessage['false']['file']['url'];  
  125. returnfalse;  
  126. }  
  127. }  

 

相关内容

热门资讯

如何允许远程连接到MySQL数... [[277004]]【51CTO.com快译】默认情况下,MySQL服务器仅侦听来自localhos...
如何利用交换机和端口设置来管理... 在网络管理中,总是有些人让管理员头疼。下面我们就将介绍一下一个网管员利用交换机以及端口设置等来进行D...
施耐德电气数据中心整体解决方案... 近日,全球能效管理专家施耐德电气正式启动大型体验活动“能效中国行——2012卡车巡展”,作为该活动的...
20个非常棒的扁平设计免费资源 Apple设备的平面图标PSD免费平板UI 平板UI套件24平图标Freen平板UI套件PSD径向平...
德国电信门户网站可实时显示全球... 德国电信周三推出一个门户网站,直观地实时提供其安装在全球各地的传感器网络检测到的网络攻击状况。该网站...
为啥国人偏爱 Mybatis,... 关于 SQL 和 ORM 的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行...
《非诚勿扰》红人闫凤娇被曝厕所... 【51CTO.com 综合消息360安全专家提醒说,“闫凤娇”、“非诚勿扰”已经被黑客盯上成为了“木...
2012年第四季度互联网状况报... [[71653]]  北京时间4月25日消息,据国外媒体报道,全球知名的云平台公司Akamai Te...