PHP上傳類實現單個和批量上傳_PHP教程

來源:互聯網
上載者:User
PHP上傳類還是比較常用的,於是我研究了一下PHP上傳類,在這裡拿出來和大家分享一下,希望對大家有用。PHP本身是一種簡單而強大的語言。PHP語言擁有核心特性如強大的字串和數組處理能力,同時極大的改進了對物件導向編程的支援(PHP5以上版本)。

通過使用標準的和可選的擴充模組,PHP應用程式可以串連MySQL或Oracle等十幾種資料庫、繪圖、建立PDF檔案和建立解析XML檔案。你也可以使用C語言來寫自己的PHP擴充模組。例如,在已存在的程式碼程式庫中提供一個PHP的介面函數。你也可以在Windows下運行PHP,使用COM控制其它諸如Word和Excel的Windows應用程式,或者使用ODBC來串連資料庫。在國內,PHP曾經和微軟的ASP並駕齊驅,是大家常用的網路程式設計語言。 

PHP上傳類代碼:

 
  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. 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. include_once(SERVERROOT.MYFRAME.'myFrame_Basic.php');
  59. /**
  60. *thefollowingforsingle
  61. */
  62. if($outPutName==''||$outPutName=="NULL")
  63. {
  64. $outPutName=date("YmdHis");
  65. }
  66. if($VALUE['error']>0)
  67. {
  68. switch($VALUE['errror'])
  69. {
  70. case'1':
  71. $this->errorMessage[]=$this->myFrameMessage['false']['file']['max'];
  72. returnfalse;
  73. break;
  74. case'2':
  75. $this->errorMessage[]=$this->myFrameMessage['false']['file']['maxDefined'];
  76. returnfalse;
  77. break;
  78. case'3':
  79. $this->errorMessage[]=$this->myFrameMessage['false']['file']['uncomplite'];
  80. returnfalse;
  81. break;
  82. case'4':
  83. $this->errorMessage[]=$this->myFrameMessage['false']['file']['unupload'];
  84. returnfalse;
  85. break;
  86. }
  87. }
  88. $fileName=$this->uploadPath.$outPutName.myFrame_Basic::getFileName($VALUE['name']).myFrame_Basic::getFileExt($VALUE['name']);
  89. if(is_uploaded_file($VALUE['tmp_name']))
  90. {
  91. if(!move_uploaded_file($VALUE['tmp_name'],$fileName))
  92. {
  93. $this->errorMessage[]=$this->myFrameMessage['false']['file']['move'];
  94. returnfalse;
  95. }else{
  96. return$fileName;
  97. }
  98. }
  99. }
  100. /**
  101. *Uploadfromnetwork
  102. *
  103. *@paramArray|String$url
  104. *@paramArray|String$outPutName
  105. *@paramBool$keepSource
  106. */
  107. publicfunctionfromNet($url,$outPutName='',$keepSource=false)
  108. {
  109. include_once(SERVERROOT.MYFRAME.'myFrame_Basic.php');
  110. if($outPutName=="")
  111. {
  112. $outPutName=date("YmdHis");
  113. }
  114. $fileType=myFrame_Basic::getFileExt($url);
  115. $fileName=$outPutName.$fileType;
  116. $contents=file_get_contents($url);
  117. $return=file_put_contents($this->uploadPath.$fileName,$contents);
  118. if($return){
  119. $this->fullPath=$this->uploadPath.$fileName;
  120. return$this->fullPath;
  121. }else{
  122. $this->errorMessage[]=$this->myFrameMessage['false']['file']['url'];
  123. returnfalse;
  124. }
  125. }
  126. }


http://www.bkjia.com/PHPjc/446547.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/446547.htmlTechArticlePHP上傳類還是比較常用的,於是我研究了一下PHP上傳類,在這裡拿出來和大家分享一下,希望對大家有用。PHP本身是一種簡單而強大的語言...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.