PHP Upload class for single and batch uploads

Source: Internet
Author: User

PHP Upload classes are quite common, So I studied the PHP Upload class and shared it with you here. I hope it will be useful to you. PHP itself is a simple and powerful language. PHP has core features such as powerful string and array processing capabilities, and greatly improved support for Object-Oriented Programming (PHP5 and later versions ).

Using standard and optional extension modules, PHP applications can connect to more than a dozen databases such as MySQL or Oracle, draw, create PDF files, and create parsed XML files. You can also use the C language to write your own PHP extension module. For example, provide a PHP interface function in an existing code library. You can also run PHP In Windows, use COM to control other Windows applications such as Word and Excel, or Use ODBC to connect to the database. In China, PHP is a commonly used network programming language.

PHP Upload code:

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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.